Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 01-30-2008, 03:24 AM newbie needing help!
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
First of all, hello everyone.. newbie here both to the forum and php and already getting confused

Right

i have a database and need to know how i can do something with it with php

i have this as the fields

Profiles
ID ( primary key )
City

I am trying to get my php script to check to see if member has anything entered in the city field, if its blank it then takes them to a page, if its filled out it take them to another page

i already know the ID number so don't need to be a search, just a direct hit to that place

so kind of like this


<?php
mysql.. checks if the City field is blank or not
if blank
echo "<script language=\"Javascript\">location.href = 'blank.php';</script>\n";
else
echo "<script language=\"Javascript\">location.href = 'notblank.php';</script>\n";
?>


i know its not real hard if you know what you are doing and i did just about manage to do it at one point but was also getting an error display before it redirected to next page but i am soooooooo confused and been trying to work it out for 4 hours now

please can someone help

loads of thanks

Shaz x
Sharon_leic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-30-2008, 04:52 AM Re: newbie needing help!
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Hi Newbie and welcome to the neighbourhood

No need to use JS - make use of phps header function.http://uk.php.net/header


Code:
 <?php
mysql.. checks if the City field is blank or not
if (...blank...)
  { header("Location: blank.php");
  }
else
  { header("Location: not_blank.php");
  }
?>
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 09:38 AM Re: newbie needing help!
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Hiya

my script is called by another script ( include ) so i get a "header already sent" message if i don't use javascript

oh and there is stuff written before the calling of this script to and that stops header("Location: not_blank.php") from working

its not that part thats causing the problem though

its the checking the mysql bit i can't work out

mysql.. checks if the City field is blank or not

anyone know how?

shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!

Last edited by Sharon_leic; 01-30-2008 at 09:44 AM..
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 09:52 AM Re: newbie needing help!
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
You need to post the whole script.
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 10:03 AM Re: newbie needing help!
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Quote:
Originally Posted by maxxximus View Post
You need to post the whole script.

that is the whole script lol

i need mysql to check in

profiles WHERE City at ID

i know this isn't correct but something like this...

these are the database field i need to check
ID > profiles > City ( i will already have the ID number)

<?php
$result = mysql_query("SELECT City FROM Profiles WHERE ID=$memberID");
if result = ( what ever is used to see if a field is blank )


echo "<script language=\"Javascript\">location.href = 'blank.php';</script>\n";
else
echo "<script language=\"Javascript\">location.href = 'notblank.php';</script>\n";
?>

its the 2 lines in bold i cant work out
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 10:15 AM Re: newbie needing help!
Extreme Talker

Posts: 182
Trades: 0
Hello!

You simply need to check for results.

The simplest way:

PHP Code:
$sql "SELECT City FROM Profiles WHERE ID=" $memberID;
$query mysql_query$sql );
$numrows mysql_num_rows $query );

if ( 
$numrows )
{
  
// a hit!
}
else
{
  
// no dice, sucka!

bhgchris is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 10:28 AM Re: newbie needing help!
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Quote:
Originally Posted by bhgchris View Post
Hello!
Hiya

that seems to look more like what i want

this is the code i now have

<?php
$sql = "SELECT City FROM Profiles WHERE ID=" . $memberID;
$query = mysql_query( $sql );
$numrows = mysql_num_rows ( $query );

if ( $numrows < 1 )
{
echo "<script language=\"Javascript\">location.href = 'blankprofile.php';</script>\n";
}
else
{ }
?>

what the idea is to do, when a member logs in, it calls this script with ( include ), checks to see if there profile is filled in ( by looking at city field as that is a mandatory field they have to fill in when editing profile ) if profile isn't filled in it then takes them to a page to ask them to fill it in..

if it is filled in then it does nothing.. note the
else { }

however, although this don't return any errors, its not working yet lol

p.s
my field city will have a city in it, this is text.. example.. leicester

in edit
i stuck in there
echo $numrows;
but see its returning number 1 even if the fielt city is blank so that would be why its doing nothing wouldn't it?
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!

Last edited by Sharon_leic; 01-30-2008 at 10:39 AM..
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 10:46 AM Re: newbie needing help!
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
right hehe i am confusing myself now

to keep this simple

this is the code i have

<?php
$sql = "SELECT City FROM Profiles WHERE ID=" . $memberID;
$query = mysql_query( $sql );
$numrows = mysql_num_rows ( $query );
echo $numrows;
if ( $numrows < 1 )
{
echo "<script language=\"Javascript\">location.href = 'blankprofile.php';</script>\n";
}
else
{ }
?>


when my field CITY is blank this script should redirect people to a new page
if it has something entered then it does nothing
currently $numrows; is returning number 1 no matter if city field is blank or not.
can you help me please?
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 10:50 AM Re: newbie needing help!
Extreme Talker

Posts: 182
Trades: 0
oops, I totally missed that part.

You have some different options:

1) adding to the query
PHP Code:
# Only grabs a row if the ID matches and City isn't empty
$sql "SELECT City FROM Profiles WHERE ID=" $memberID " AND City != '' "

# This would work too
$sql "SELECT City FROM Profiles WHERE ID=" $memberID " AND City IS NOT NULL' "
2) check result with php

PHP Code:
$sql "SELECT City FROM Profiles WHERE ID=" $memberID;
$query mysql_query$sql );
$result mysql_fetch_assoc $query );

# Note: I capitalized 'City' because I noticed you did. This is case sensitive!
if ( !empty ( $result ['City'] ) )
{
  
// yay, a city!
}
else

  
// ew, no city =(

Both should work, second is probably best. Let me know!
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 11:02 AM Re: newbie needing help!
Extreme Talker

Posts: 182
Trades: 0
Quote:
Originally Posted by Sharon_leic View Post
in edit
i stuck in there
echo $numrows;
but see its returning number 1 even if the fielt city is blank so that would be why its doing nothing wouldn't it?
That's because it was getting a hit. MySQL was grabbing `City` from the table where `ID` = $memberid. It was only checking to make sure that `ID` matched $memberid, not that `ID` matched AND `City` was empty.

My last reply should fix that
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 11:03 AM Re: newbie needing help!
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
bhgchris, Your a star and a 1/2!

it now works, this is the code i finished of with and works like a dream hehe

<?php
$sql = "SELECT City FROM Profiles WHERE ID=" . $memberID . " AND City != '' ";
$query = mysql_query( $sql );
$numrows = mysql_num_rows ( $query );
if ( $numrows < 1 )
{echo "<script language=\"Javascript\">location.href = 'blankprofile.php';</script>\n"; }
else
{}
?>

thankyou sooooooo much

why is php so complicated, why can't it be as simple as
10 for x = 1 to 500
20 print " we are at number ": print x
30 next x
40 Print " we finished!"

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 02:50 PM Re: newbie needing help!
Extreme Talker

Posts: 182
Trades: 0
Glad it worked out for you!

PHP can be as complicated as you want to make it.

Plus, you can usually get great help here
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 01-30-2008, 10:09 PM Re: newbie needing help!
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
actually the code i posted in last post that i said was right was an old one that didn't work

this is the one that does work lol

<?php
$sql = "SELECT City FROM Profiles WHERE ID=" . $memberID;
$query = mysql_query( $sql );
$result = mysql_fetch_assoc ( $query );
if ( !empty ( $result ['City'] ) )
{}
else
{echo "<script language=\"Javascript\">location.href = 'blankprofile.php';</script>\n"; }
?>

thanks for your help..

and yes, some very knowledgeable people here

now just a .htaccess problem i need to fix grrr

thanks again

Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to newbie needing help!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 2.13570 seconds with 12 queries