How to disable duplicate records on PHP mySQL database.?
Do you have any idea how to save data on php mysql database with no duplicates. Do you have codes that won't let then user enter identical records to a database? please help! Thanks!
I don't see any apparent mistakes. The great option to troubleshoot it is to echo $qry earlier than you run it and take a look at it in phpmyadmin. You might additionally wish to affirm that your mysql_connect and mysql_select_db are great with the aid of appending "or die(mysql_error($res))". EDIT: the opposite answerer's correct on the fact that no row will get returned. I also wanted so as to add that this script will have to in no way be made available online because it has critical protection flaws. One would easily wipe out your whole database with it.
you can make use of phpMyAdmin to manage the database , when you create the database you can make the field unuiqe , or run a query to see if the data already exists before you update the database with a if statement, if data exist display echo "no duplicates allowed" id not update or insert
Answers & Comments
Verified answer
$count=mysql_num_rows(mysql_query("select field_name from table_name where fields = new_data"));
if ($count>0)
{
echo "duplicate record";
}
else
{
mysql_query("insert into table_name (fields) values (new_data)");
}
is that what you're looking for?
I don't see any apparent mistakes. The great option to troubleshoot it is to echo $qry earlier than you run it and take a look at it in phpmyadmin. You might additionally wish to affirm that your mysql_connect and mysql_select_db are great with the aid of appending "or die(mysql_error($res))". EDIT: the opposite answerer's correct on the fact that no row will get returned. I also wanted so as to add that this script will have to in no way be made available online because it has critical protection flaws. One would easily wipe out your whole database with it.
you can make use of phpMyAdmin to manage the database , when you create the database you can make the field unuiqe , or run a query to see if the data already exists before you update the database with a if statement, if data exist display echo "no duplicates allowed" id not update or insert