-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook.php
55 lines (47 loc) · 1.92 KB
/
book.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
$servername = "localhost";
$username = "root"; // Replace with your MySQL username
$password = ""; // Replace with your actual password
$dbname = "my database"; // Replace with your database name
// Establish connection
try {
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
throw new Exception("Connection failed: " . $conn->connect_error);
}
// Check if form is submitted using POST
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = mysqli_real_escape_string($conn, $_POST["name"]);
$number_of_people = mysqli_real_escape_string($conn, $_POST["number"]);
$email = mysqli_real_escape_string($conn, $_POST["email"]);
$passport_number = mysqli_real_escape_string($conn, $_POST["number"]);
$whatsapp_number = mysqli_real_escape_string($conn, $_POST["telephone"]);
// Prepare the form to be submitted with error handling
$sql = "INSERT INTO `ORDE` (`NAME`, `NUMBER_OF_PEOPLE`, `EMAIL`, `PASSPORT_NUMBER`, `WHATSAPP_NUMBER`) VALUES (?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
if ($stmt === false) {
throw new Exception("Error preparing statement: " . $conn->error);
}
// Bind parameters to prevent SQL injection with data type checks
$data_types = "sssss"; // Assuming all are strings
if (is_numeric($number_of_people)) {
$data_types = "sisss"; // Change to "i" for integer
}
$stmt->bind_param($data_types, $name, $number_of_people, $email, $passport_number, $whatsapp_number);
// Execute the statement with error handling
if ($stmt->execute() === true) {
echo "Request sent, our team will respond soon.";
} else {
throw new Exception("Error executing statement: " . $stmt->error);
}
// Close the prepared statement
$stmt->close();
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
} finally {
// Close the connection
$conn->close();
}
?>