Page 1 of 1
Username Checking from SQL Database
Posted: Mon Jul 28, 2003 9:50 pm
by kkurkowski
I am looking for a piece of code tha checks the username in the database if it is registered yet, if it isn't registered then go back to the signup page saying username in use. Anybody got any idea's? Username name on form is username
Posted: Mon Jul 28, 2003 9:57 pm
by Drachlen
Code: Select all
<?php
$name_check = mysql_query("SELECT username FROM user_table WHERE username='$username'", $link) or die(mysql_error());
if (mysql_num_rows($name_check) == 1) {
//Name is taken
} else {
//Name is not taken
}
?>
This should do the trick =)
Posted: Mon Jul 28, 2003 10:07 pm
by kkurkowski
What is the $link @ the end of the mysql_qurey statement? I am getting a error on that line for it.
Line 13: $name_check = mysql_query("SELECT username FROM $table_name WHERE username='$username'", $link) or die(mysql_error());
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/html/signup_complete.php on line 13
Posted: Mon Jul 28, 2003 10:13 pm
by Drachlen
Ahh, my bad, i just connect using:
Code: Select all
<?php
$link = mysql_connect("localhost", "*", "*")
or die("Could not connect");
mysql_select_db("your_DB", $link) or die("Could not select database");
?>
Posted: Mon Jul 28, 2003 10:18 pm
by kkurkowski
ahhh, i c now. I should be ok from here now. Thanks.