Username Checking from SQL Database

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
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Username Checking from SQL Database

Post 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
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post 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 =)
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post 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
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post 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");

?>
kkurkowski
Forum Commoner
Posts: 53
Joined: Mon Dec 09, 2002 4:44 pm
Location: Michigan

Post by kkurkowski »

ahhh, i c now. I should be ok from here now. Thanks.
Post Reply