i have small php form with with id, firstname, lastname, mobileno , in which id is primary key which auto incremented where as mobileno column set unique in mysql table. I wanted to generate error message if duplicate mobileno trying to enter in database and stop record from storing in database. (duplicate error message need to be generated at front end (form page) rather than form.php file)Here is my php code
<form method="POST" action="form1.php">
<label>firstname</labe><input type = text name = "fname" id = :"fname">
<label>Last name</labe><input type = text name = "lname" id = :"lname">
<label>Mobile No</labe><input type = text name = "mob" id = :"mob">
<input type = "submit" value = "submit">
</form>
here is form.php file
<?php
// getting all values from the HTML form
if(isset($_POST['submit']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mob = $_POST[mob'];
}
$sql = "INSERT INTO iap2 (fname, lname, mob)
VALUES ('$fname', '$lname', '$mob')";
// send query to the database to add values and confirm if successful
$rs = mysqli_query($con, $sql);
if($rs)
{
echo "record already exists";
}
// close connection
mysqli_close($con);
?>