Check against mysql field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Check against mysql field

Post by Jim_Bo »

Hi,

I am trying to check that a username exists before continung with the script .. With the code below it says invalid username .. when the name does exist in the database ..

Code: Select all

$sql_user_name_check = mysql_query("SELECT user_name FROM users WHERE user_name = '$user_name'"); 
  
$user_name_check = mysql_num_rows($sql_user_name_check); 

if($user_name_check == 0) 
{ 

echo "<b>Error</b>: Username doesn't exist .<p> <a href=\"../index.php?pages=compose\">BACK</a></p>"; 

return;
Im guesing its because username cant be set as user_name .. it must be username .. ?

The database field title is user_name ..

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

echo out the query string.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

?? not sure what you mean .. I had the same setup using alias instead of user_name and that seemed to work fine ..

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

echo "SELECT user_name FROM users WHERE user_name = '$user_name'";
:roll:
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

Omg .. forget I asked .. so easy to miss simple things .. Missed one variable in a form :oops:

Thanks ..
Post Reply