Username Checking from SQL Database
Moderator: General Moderators
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
Username Checking from SQL Database
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
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
}
?>-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
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
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
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