I have a form that accepts multiple inputs and then submits it to the database however there is a field which holds the certificate number for a record I would like to query the database before the data is inserted to ensure that the certificate number is not already present. Can i do this when the field is entered i.e when the user tabs out of the field and then display a notification?
If so can someone post an example on how to do this.
The MySQL table is called – contract
The MySQL field is called – guarantee_no
The Form POST’s to create.php (Code Below)
<?php
include "includes/connection.php";
$installer = $_POST['inputInstaller'];
$fitter = $_POST['inputFitter'];
$guarantee = $_POST['inputGuaratnee_no'];
$equipment = $_POST['inputEquipment'];
$certificate = $_POST['inputCertificate_no'];
$installed = $_POST['inputInstall_date'];
if(!$_POST['submit']){
echo "Please Enter Data into the Form";
printf("<script>location.href='index.php'</script>");
} else {
mysql_query("INSERT INTO contract (`id`,`user_id`,`installer`,`fitter`,`guarantee_no`,`contact_id`,`equipment`,`certificate_no`,`install_date`)
VALUES(NULL,'1','$installer','$fitter','$guarantee',NULL,'$equipment','$certificate','$installed')") or die(mysql_error());
echo "Guarantee Record was Added, Thank You!";
printf("<script>location.href='index.php'</script>");
}
?>
Thanks for your help in advance
According to your Question. If you want to use that validation in PHP. You can use
$_SESSIONvariables.In your action file.
Use:
Now in your
index.phpfile.Use at the top:
Now use that
$msgvariable where you want to print the message.like:
Note: If you dont want to reload the page then Ajax with PHP should be used. This is just the simple way. You can Use accordingly.
Hope It helps..cheers..!!