-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChekout.php
73 lines (62 loc) · 2.08 KB
/
Chekout.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *'); // Allow CORS
header('Access-Control-Allow-Methods: GET'); // Specify allowed methods
header('Access-Control-Allow-Headers: Content-Type');
// Include database connection configuration
include "Conx.php"; // Ensure this file contains your database credentials
// Check if the user ID is provided
if (!isset($_GET['user_id'])) {
echo json_encode([
'success' => false,
'message' => 'User ID is missing in the request.'
]);
exit;
}
$user_id = intval($_GET['user_id']); // Sanitize user ID
// Establish a database connection
$conn = mysqli_connect($host, $username, $password, $dbname);
// Check for connection errors
if (!$conn) {
echo json_encode([
'success' => false,
'message' => 'Database connection failed: ' . mysqli_connect_error()
]);
exit;
}
// Fetch user details for the given user ID
$sql = "SELECT name, phone, email FROM users WHERE id = ?";
$stmt = mysqli_prepare($conn, $sql);
if ($stmt) {
mysqli_stmt_bind_param($stmt, "i", $user_id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$user = mysqli_fetch_assoc($result);
if ($user) {
// Example: Hardcoding cart items for now
$cartItems = [
['product_name' => 'Test Product 1', 'quantity' => 1, 'price' => 20],
['product_name' => 'Test Product 2', 'quantity' => 2, 'price' => 30]
];
$grandTotal = 80; // Hardcoded grand total
echo json_encode([
'success' => true,
'user' => $user,
'cartItems' => $cartItems,
'grandTotal' => $grandTotal
]);
} else {
echo json_encode([
'success' => false,
'message' => 'User not found.'
]);
}
mysqli_stmt_close($stmt);
} else {
echo json_encode([
'success' => false,
'message' => 'Failed to prepare the SQL query: ' . mysqli_error($conn)
]);
}
mysqli_close($conn);
?>