girlzz Posted July 28, 2008 Share Posted July 28, 2008 i need some help... newbie and not very familiar with php... how to write a code using php if want to check there is data in database or not so that there is no duplicate entry in the database with alert message... Link to comment https://forums.phpfreaks.com/topic/116995-solved-how-to-makesure-no-duplicate-entries-with-alert-box/ Share on other sites More sharing options...
pocobueno1388 Posted July 28, 2008 Share Posted July 28, 2008 <?php $query = mysql_query("SELECT COUNT(*) FROM table WHERE data='$data'"); $num = mysql_num_rows($query); if ($num > 0){ echo "Duplicate!!"; } ?> Link to comment https://forums.phpfreaks.com/topic/116995-solved-how-to-makesure-no-duplicate-entries-with-alert-box/#findComment-601681 Share on other sites More sharing options...
revraz Posted July 28, 2008 Share Posted July 28, 2008 There is also a nice little Function I posted awhile back called checkUnique. I'm sure if you search for it, you'll find it. Link to comment https://forums.phpfreaks.com/topic/116995-solved-how-to-makesure-no-duplicate-entries-with-alert-box/#findComment-601685 Share on other sites More sharing options...
trq Posted July 28, 2008 Share Posted July 28, 2008 <?php $query = mysql_query("SELECT COUNT(*) FROM table WHERE data='$data'"); $num = mysql_num_rows($query); if ($num > 0){ echo "Duplicate!!"; } ?> mysql_num_rows() will always return 1 row using this method, unless of course the query fails. Try... if ($result = mysql_query("SELECT COUNT(*) FROM table WHERE data='$data'")) { if (mysql_result($res,0) > 0) { echo "Duplicate!!"; } } Link to comment https://forums.phpfreaks.com/topic/116995-solved-how-to-makesure-no-duplicate-entries-with-alert-box/#findComment-601696 Share on other sites More sharing options...
girlzz Posted July 28, 2008 Author Share Posted July 28, 2008 thanks a lot... i had change my table field with unique.. but just incase i want to make an alert popup box just to remind user if they had enter duplicate entries... Link to comment https://forums.phpfreaks.com/topic/116995-solved-how-to-makesure-no-duplicate-entries-with-alert-box/#findComment-601709 Share on other sites More sharing options...
trq Posted July 28, 2008 Share Posted July 28, 2008 Is that another question? Pop-up boxes are done client-side using javascript. Link to comment https://forums.phpfreaks.com/topic/116995-solved-how-to-makesure-no-duplicate-entries-with-alert-box/#findComment-601712 Share on other sites More sharing options...
girlzz Posted July 28, 2008 Author Share Posted July 28, 2008 that is not a question.. sorry... Link to comment https://forums.phpfreaks.com/topic/116995-solved-how-to-makesure-no-duplicate-entries-with-alert-box/#findComment-601726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.