Hello guys! I'm creating a login/logout script, the script is working fine but it is not very well featured, i would like to put a restriction that when someone tries to signup with same username or same email that is signed up before, it should give an error. I tried somefin like if($fieldname['username'] == $_POST['username']) { // give an error } but this doesn't seem to work. $fieldname is an array fetching data from mysql. and $_POST['username'] is the username that will be used on signup, please guide me on where i'm wrong or what should i do to put a restriction.. thanks in advance.
Something like... $username = mysql_real_escape_string(get_magic_quotes_gpc() ? stripslashes($_POST['username'] : $_POST['username']); PHP: Then a query similar to... SELECT count(id) as COUNT FROM database WHERE username = '$username' LIMIT 1; Code (markup): Then if(mysql_result($result, 0, 'COUNT') > 0) $errors[] = 'Username already exists.'; PHP: This is MUCH faster than retrieving all the rows and using an in_array() to check.
wow, it worked. Thank you so much. About that mysql_real_escape.... thing, i already did that. Thanks anyways. + For you!