-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_order.php
47 lines (37 loc) · 1.45 KB
/
process_order.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
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user_id = $_SESSION['user_id'];
$product_id = 1; // Adjust this based on your product
$quantity = 1; // Adjust this based on the quantity ordered
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$postal_code = $_POST['postal_code'];
$country = $_POST['country'];
// Establish database connection
$host = "database"; // Docker service name for the MySQL container
$username = "devuser"; // MySQL username
$password = "root"; // MySQL password
$database = "devops"; // MySQL database name
$conn = mysqli_connect($host, $username, $password, $database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Insert order into database
$sql = "INSERT INTO orders (user_id, product_id, quantity, address, city, state, postal_code, country)
VALUES ($user_id, $product_id, $quantity, '$address', '$city', '$state', '$postal_code', '$country')";
if ($conn->query($sql) === TRUE) {
// Order placed successfully
echo "Order placed successfully!";
// Redirect or display confirmation message
} else {
echo "Error placing order: " . $conn->error;
}
$conn->close();
}
?>