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 Link to comment https://forums.phpfreaks.com/topic/51404-solved-phpmysql-checking-for-duplicates-in-database/ 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"; } Link to comment https://forums.phpfreaks.com/topic/51404-solved-phpmysql-checking-for-duplicates-in-database/#findComment-253139 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. Link to comment https://forums.phpfreaks.com/topic/51404-solved-phpmysql-checking-for-duplicates-in-database/#findComment-253158 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? Link to comment https://forums.phpfreaks.com/topic/51404-solved-phpmysql-checking-for-duplicates-in-database/#findComment-253160 Share on other sites More sharing options...
laron Posted May 15, 2007 Author Share Posted May 15, 2007 yes for both questions Link to comment https://forums.phpfreaks.com/topic/51404-solved-phpmysql-checking-for-duplicates-in-database/#findComment-253267 Share on other sites More sharing options...
btherl Posted May 15, 2007 Share Posted May 15, 2007 Please post your code Link to comment https://forums.phpfreaks.com/topic/51404-solved-phpmysql-checking-for-duplicates-in-database/#findComment-253347 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 Link to comment https://forums.phpfreaks.com/topic/51404-solved-phpmysql-checking-for-duplicates-in-database/#findComment-254103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.