Repository navigation
Expand file tree
/
Copy pathcheckout_process.php
More file actions
56 lines (42 loc) · 1.67 KB
/
Copy pathcheckout_process.php
File metadata and controls
56 lines (42 loc) · 1.67 KB
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
56
<?php
session_start();
// Assuming you have a database connection, replace the placeholders with your actual database connection details
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "saplingo";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve form data
$productId = $_POST['productId'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$location = $_POST['pickuppoint'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$totalPrice = $_POST['totalPrice'];
$uid = $_SESSION['uid']; // Assuming you have a 'uid' key in your session.
$productId = $_POST['productId'];
$quantity = $_POST['quantity'];
$sql = "UPDATE sales_items SET quantity = quantity - $quantity WHERE SI_id = '$productId'";
mysqli_query($conn, $sql);
// Insert data into the 'order' table
$sql = "INSERT INTO `order` ( uid, item_id, firstname, lastname, location, phone, email, totalprice, status)
VALUES ('$uid', '$productId', '$firstname', '$lastname', '$location', '$phone', '$email', '$totalPrice','placed')";
if ($conn->query($sql) === TRUE) {
// Redirect to index.php after successful order placement
header("Location: index.php?order_posted=1");
exit(); // Ensure that no further code is executed after the redirect
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
echo '<br><a href="shop.php"><button>Back To Shop</button></a>';
}
// Your database connection code here
// Your SQL query to update the quantity in the database
// Close the database connection
$conn->close();
?>