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
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Fri Feb 18, 2005 6:31 am
Hey,
This checks if the user name allready exists in the databse .. How do you do the opposite and make sure the user name exists or die
Code: Select all
$sql_username_check = mysql_query("SELECT user_name FROM users WHERE user_name='$user_name'");
$username_check = mysql_num_rows($sql_username_check);
if($username_check > 0){
echo "<b>Error</b> Username doesnt exist";
echo "<p><a href="../index.php?pages=form">BACK</a></p>";
return;
}
Thanks
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Feb 18, 2005 6:37 am
Is it me or does your question not make any sense
what's wrong with what you have? This will check if no rows are returned spit out an error, else, do whatever you need with the username
Code: Select all
$sql_username_check = mysql_query("SELECT user_name FROM users WHERE user_name='$user_name'");
$username_check = mysql_num_rows($sql_username_check);
if($username_check == 0)
{
echo "<b>Error</b> Username doesnt exist
<p><a href="../index.php?pages=form">BACK</a></p>";
}
else
{
//do what you want with unique username
}
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Fri Feb 18, 2005 6:58 am
Hey,
It doesnt make sence ..
I need it to check that the username exists .. if it does carry on and exicute the script .. if it doesnt exist fail and show the form again ..
The posted code does the following .. it fails if the username exists and exicutes the script if it doesnt ..
Thanks
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Fri Feb 18, 2005 7:06 am
This script is alright. You are somewhat confused
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Fri Feb 18, 2005 7:11 am
hey,
Nope im not confused ..
If the user name exists the script fails ..
If the user name doesnt exist .. it carrys on and exicutes the rest of the script ..
I want it to check that the user name exists .. if it does .. carry on with the script .. If the user name doesnt exist in the database .. then stop the script and show error message ..
Thanks
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Fri Feb 18, 2005 7:17 am
OK Maybe this is what you want
Code: Select all
$sql_username_check = mysql_query("SELECT user_name FROM users WHERE user_name='$user_name'");
$username_check = mysql_num_rows($sql_username_check);
if($username_check == 0)
{
die("<b>Error</b>: Username doesn't exist .<p>
<a href="../index.php?pages=form">BACK</a></p>");
}
Jim_Bo
Forum Contributor
Posts: 390 Joined: Sat Oct 02, 2004 3:04 pm
Post
by Jim_Bo » Fri Feb 18, 2005 7:31 am
Hey,
Thats what im after ..
Thanks
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Fri Feb 18, 2005 10:16 am
die() is typically used when something is happening that shouldn't. The code I did for you will not execute anything in the else statement if no user is found.
Why do you need the script to terminate?