laron Posted May 14, 2007 Share Posted May 14, 2007 Hey, quick question(hopefully), how can i check for duplicates in a database. For instance, checking for already registered users, etc. thanks Quote Link to comment Share on other sites More sharing options...
btherl Posted May 14, 2007 Share Posted May 14, 2007 If checking if a new user has the same name as an old user, something like this is enough: $sql = "SELECT * FROM users WHERE username = '$new_user'"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { print "$new_user already exists!\n"; } else { print "$new_user really is new!\n"; } Quote Link to comment Share on other sites More sharing options...
laron Posted May 15, 2007 Author Share Posted May 15, 2007 i get an error that says query was empty. Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 15, 2007 Share Posted May 15, 2007 Did you change the table names and the variable names to what you have? Also, is there any records in the db? Quote Link to comment Share on other sites More sharing options...
laron Posted May 15, 2007 Author Share Posted May 15, 2007 yes for both questions Quote Link to comment Share on other sites More sharing options...
btherl Posted May 15, 2007 Share Posted May 15, 2007 Please post your code Quote Link to comment Share on other sites More sharing options...
laron Posted May 16, 2007 Author Share Posted May 16, 2007 nevermind, figured it out... thanks for the code(i made some errors changing it to fit my database) thanks and solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.