-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.php
31 lines (24 loc) · 1.16 KB
/
checkout.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
<!--checkout.php-->
<!--Author: Alexis Demetriou (G20970098)-->
<!--Email: [email protected]>
<?php
session_start();
include "connect.php";
// Get the cart data from local storage
$cartData = json_decode($_POST['cartData'], true);
// Prepare the order data
$order_date = date("Y-m-d H:i:s"); // Get the current date and time
$user_id = $_SESSION['user_id']; // Get the user ID from the session
$product_ids = implode(",", array_column($cartData, 'product_id')); // Get a comma-separated list of product IDs from the cart data
// Insert the order into the tbl_orders table
$query = "INSERT INTO tbl_orders (order_date, user_id, product_ids) VALUES ('$order_date', '$user_id', '$product_ids')";
if (mysqli_query($connection, $query)) { // If the query was successful
echo "<script>
alert('Your order has been successfully placed!'); // Show a success message
window.location.href = 'cart.php'; // Redirect the user to the cart page
</script>";
} else {
echo "ERROR: could not insert order: " . mysqli_error($connection);
}
mysqli_close($connection);
?>