I'm writing a form where I want the code to check if the inserted 'date' on which a participant wants to attend an event matches a 'date' in my events table. For the moment (even though 'date' as on the form input doesn't match any of the dates on the events table) users can register for any date without getting the validation error.
on the html-form "register.html" I have:
<form action="register.php" method="post">
<div class="form-group">
<label for="date"> Date of attendence </label>
<input type="date" class="form-control" id="date" name="date"/>
</div>
<input type="submit" class="btn btn-primary" />
</form>
on "register.php" I have:
<?php
$date = $_POST['date'];
$conn = new mysqli('localhost','root','','skay');
if($conn->connect_error){
echo "$conn->connect_error";
die("Connection Failed : ". $conn->connect_error);
} else {
$date_check_query = "SELECT COUNT * FROM events WHERE date='$date'";
$number_of_matches = mysqli_query($conn, $date_check_query);
if ($number_of_matches = 0) {
array_push($errors, "No planned events on this day");
} else {
$stmt = $conn->prepare("INSERT INTO registrations(date) values(?)");
$stmt->bind_param("sssssi", $date); //there are other 5 other values aswell
$execval = $stmt->execute();
echo $execval;
echo "Registration successfully...";
$stmt->close();
$conn->close();
}
}
?>
Grtz Beau