-2
$fname=$_POST['fname'];
$lname = $_POST['lname'];
$Phone = $_POST['Phone'];
$date = date("Y/m/d");
mysql_query ( "INSERT INTO example (fname,lname,Phone,date) VALUES ('$fname' ,'$lname', '$Phone', '$date')")

or die(mysql_error());  

when i write a duplicate entry in my codes these Error will display: my PRIMARY key is Phone.

  Duplicate entry '' for key 'PRIMARY'

but i want to check and display by JavaScript to Prevent this Error before adding data. how is it possible? please help completely and wire source. thanks

5

1 Answer 1

0
$fname=$_POST['fname'];
$lname = $_POST['lname'];
$Phone = $_POST['Phone'];
$date = date("Y/m/d");

$query = "SELECT * FROM example WHERE Phone =    '".mysql_real_escape_string($_POST['Phone'])."'";
if (mysql_num_rows(mysql_query($query)) > 0)
{ 
print "inuse";
} 
 else
{
 mysql_query ( "INSERT INTO example (fname,lname,Phone,date) VALUES ('$fname'   ,'$lname', '$Phone', '$date')")

or die(mysql_error());  
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.