Hi, I want to change this so instead of using the values that is there e.g. if ( $username == "joe" || $username == "rony" || $username== "joo" ) I want to search a MySQL table called users to see if there is a match. <? $action = trim($HTTP_GET_VARS['action']); ?> <? switch ( $action ): case 'validateUsername': $username = trim($HTTP_GET_VARS['username']); if ( strlen($username) >= 3 ){ if ( $username == "joe" || $username == "rony" || $username== "joo" ) print "<font color=GREEN>Username is valid</font>"; else print "<font color=RED>Username is not valid</font>"; } else{ print "<font color=RED>Username must be longer then 3 characters</font>"; } break; default: //silence is golden endswitch; ?> Code (markup): Thank you in advanced for your help. Cheers, Adam
Hi, you can probably try this SELECT * FROM users WHERE name_of_field IN ('joe','rony','joo') OR SELECT * FROM users WHERE name_of_field = 'joe' OR name_of_field = 'rony' OR name_of_field = 'joo'
Sorry i did not explain my self properly, what i meant is i want to check if the POST user name exists in the users table. So i don't want to check with certain names just all entries.
oh ok, try this then SELECT * FROM users WHERE name_of_field = '".$_POST['form_field_name']."'" Note: having the post directly in the query is not at all safe but i've used it here for brevity
$result = mysql_query("SELECT * FROM users WHERE user_name='$_POST[username]'"); if(mysql_num_rows($result)){ // show error msg here } else { // welcome new user } PHP:
I have now done this but it tell me the username is available even if it is not. <?php include("config/db.config.php"); $action = trim($HTTP_GET_VARS['action']); switch ( $action ): case 'validateUsername': $username = trim($HTTP_GET_VARS['username']); if ( strlen($username) >= 3 ){ $result = mysql_query("SELECT * FROM users WHERE username='$_POST[username]'"); if(mysql_num_rows($result)){ print "<font color=RED>Username has already been taken.</font>"; }else{ print "<font color=GREEN>Username is available</font>"; } }else{ print "<font color=RED>Username must be longer then 3 characters</font>"; } break; default: //silence is golden endswitch; ?> Code (markup):