Put this code near the bottom of your form. I did mine after export and placed it just above the </body> tag.
Adjust the first_name and last_name to your actual input names if different.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
var jQ = $.noConflict(true);
jQ(document).ready(function() {
jQ('#fb-submit-button').attr("disabled", true);
jQ('input[name="first_name"], input[name="last_name"]').on('change', function() {
var first_name = jQ('input[name="first_name"]').val();
var last_name = jQ('input[name="last_name"]').val();
var errorInfo = jQ("#errorInfo");
if (first_name != '' & last_name != '') {
jQ.ajax({
type: "POST",
data: {
'first_name': first_name,
'last_name': last_name
},
url: "formcheck_first_last.php",
beforeSend: function() {
errorInfo.html("<font color='blue'>Checking for member...</font>");
},
success: function(data) {
if (data != "0") {
errorInfo.html("<font color='red'>Name already exists.</font>");
jQ('#fb-submit-button').attr("disabled", true);
} else {
errorInfo.html("<font color='green'>Name doesn't exist.</font>");
jQ('#fb-submit-button').attr("disabled", false);
}
}
});
}
});
});
</script>
Add this code to your form where you want the error message to appear.
<div id="errorInfo" align="left"></div>
Take this code and create a .php page named form_check_first_last.php . Save it to the same location that your form html page is actually at. Adjust the first_name and last_name to your actual input names. Also adjust the
validation to your actual mysql table name.
<?php
require_once('pdo_connect.php');
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
if($first_name && $last_name)
{
$sql= "SELECT first_name, last_name FROM validation where first_name='$first_name' AND last_name='$last_name'";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$msg = $stmt->rowCount();
}
echo $msg;
?>
Take the code below and create a .php page named pdo_connect.php and save it to the same location that your form html page is at. Adjust the YourDataBaseName, YourUserName, YourPassword to your correct credentials.
<?php
$database = 'mysql: myHost =localhost; dbname=YourDataBaseName;charset=utf8';
$username = 'YourUserNmae';
$password = 'YourPassword';
try {
$pdo = new PDO($database, $username, $password);
$pdo ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
Helpful hint.
Create your form and submit it before you alter it. This way it will create your table and data structure.