I have made an online booking application for a small company. Where clients can book their own appointment.
Some people helped me with testing and I found a bug the next bug in my PHP error log:
Backend fatal error: PHP Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (20/01/2022, 09:00:00) at position 0 (2)
This is my code:
$email = $_GET["email"];
$start_tijd = new DateTime(date($_GET["date"]));
$end_tijd = new DateTime(date("Y-m-d H:i" , (strtotime($_GET["date"]) + 3600)));
if (isset($_GET["id"])) {
$full_name = $voornaam." ".$achternaam;
$title = "Consult ".$full_name;
}
else{
$title = $_GET["title"];
$full_name = substr($title, 8);
$clientID = last_client_id();
}
$query = "
INSERT INTO events
(title, start_event, end_event, clientID, locatie)
VALUES (:title, :start_event, :end_event, :clientID, :type)
";
$statement = $connect->prepare($query);
$statement->execute(
array(
':title' => $title,
':start_event' => $start_tijd->format('Y-m-d H:i:s'),
':end_event' => $end_tijd->format('Y-m-d H:i:s'),
':clientID' => $clientID,
':type' => $_GET["type"]
)
);
send_appointment_email($email, $full_name, $start_tijd->format('d-m-Y H:i:s'), $end_tijd->format('H:i:s'), $clientID);
About 25 people have booked an appointment and 2 people got the bug.