A person who signs on to my site will be able to choose his or her own username and password. I would like to check the username table to make sure that username doesnt already exist, if it does, prompt the user to enter a new one, if it doesnt, just continue on with the script.
Here is what i tried:
function checknameexists ($name) {
include ("customer_table.inc");
$connection = @mysql_connect("xxxx", "xxxx", "xxxx") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection)or die("Couldn't select database.");
$sql = "Select username from customer_table";
$result = @($sql,$connection)or die("Couldn't execute query.");
$namearray = 0;
$b = 0;
while ($row = mysql_fetch_array($result)){
$username = $row['username'];
$namearray[$b] = $username;
$b++;
}
$a = count($namearray);
$i=0;
while ($i <= $a) {
if ($name = $namearray[$i]) {
return FALSE;
} else {
}
$i++;
}
}
Of course, its not working, thats why im posting this. When i try it, Its always returns false, even when there is no match.
Thanks for any help