-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
39 lines (33 loc) · 1.18 KB
/
start.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
<?php
// Database connection details
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "bookshop_db"; // Replace with your actual database name
// Create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form data
$customer_name = $_POST['customer_name'];
$customer_email = $_POST['customer_email'];
$customer_phone = $_POST['customer_phone'];
$books = $_POST['books'];
// Prepare the SQL statement to insert the order into the database
$stmt = $conn->prepare("INSERT INTO orders (customer_name, customer_email, customer_phone, books) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $customer_name, $customer_email, $customer_phone, $books);
// Execute the statement and check for errors
if ($stmt->execute()) {
echo "Order placed successfully!";
} else {
echo "Error placing order: " . $stmt->error;
}
// Close the statement and the connection
$stmt->close();
$conn->close();
}
?>