Health 2007 - Debt Consolidation - Car Insurance Quotes - Find jobs - Web Design Forums

PDA

View Full Version : how to restrict double inclusion of data?


khan11
Jan 8th 2009, 7:03 am
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.

Danltn
Jan 8th 2009, 7:07 am
Something like...

$username = mysql_real_escape_string(get_magic_quotes_gpc() ? stripslashes($_POST['username'] : $_POST['username']);
Then a query similar to...
SELECT count(id) as COUNT FROM database WHERE username = '$username' LIMIT 1;
Then if(mysql_result($result, 0, 'COUNT') > 0) $errors[] = 'Username already exists.';

This is MUCH faster than retrieving all the rows and using an in_array() to check.

khan11
Jan 8th 2009, 7:35 am
wow, it worked.

Thank you so much. About that mysql_real_escape.... thing, i already did that.

Thanks anyways. + For you!