I have a PHP form which enters data into my MySQL database. My primary key is one of the user-entered values. When the user enters a value that already exists in the table,
try this code to handle duplicate entries and show echo message:
$query = "INSERT INTO ".$table_name." ".$insertdata;
if(mysqli_query($conn,$query)){
echo "data inserted into DB
";
}else{
if(mysqli_errno($conn) == 1062)
echo "duplicate entry no need to insert into DB
";
else
echo "db insertion error:".$query."
";
}//else end