I have a little problem here. I am new to either PHP and JS, so. I have a PHP code with MySQL database inside of it. In JS file I have written the code, which checks if the user's entered date is earlier or not than today's date. Now it is adding all the users to the database, but I need to add just the users which has entered earlier than today's date (add just the users with TRUE if statement). How should I do that? Thanks for any help.
Here is my part of the JS code:
if (x.getTime() < today.getTime()) {
alert ("Employees has been succesfully added to the database");
}
else
{
alert ("You have entered date which is later than todays date. Re-enter it");
}
}
Here is my PHP code:
<?php
try {
$db = new PDO( 'mysql:host=127.0.0.1;dbname=employees;charset=utf8','root','' );
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (isset($_POST['Submit'])) {
$name = $_POST['name'];
$surname = $_POST['surname'];
$employmentDate = $_POST['employmentDate'];
$insert = $db->prepare("INSERT INTO employee (name,surname,employment_date) VALUES (:name,:surname,:employmentDate)");
$insert->bindParam(':name',$name);
$insert->bindParam(':surname',$surname);
$insert->bindParam(':employmentDate',$employmentDate);
$insert->execute();
}
}
catch (PDOException $e) {
echo "There is something wrong with the database".$e->getMessage();
die();
}
?>