I try it morethan 20 times 😭😭😭😭
<?php
$dbServer = "localhost";
$dbUsername = "airfashi_sani20";
$dbPassword = "muhammad@20";
$dbName = "airfashi_fashion";
// Establish a database connection
$conn = new mysqli($dbServer, $dbUsername, $dbPassword, $dbName);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if it's a POST request
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Check if POST data is set
if (isset($_POST['reference'], $_POST['total'], $_POST['fullName'], $_POST['address'], $_POST['phoneNumber'], $_POST['deliveryType'], $_POST['productId'], $_POST['email'])) {
// Retrieve data from the POST request
$reference = $_POST['reference'];
$total = $_POST['total'];
$fullName = $_POST['fullName'];
$address = $_POST['address'];
$phoneNumber = $_POST['phoneNumber'];
$deliveryType = $_POST['deliveryType'];
$productId = $_POST['productId'];
$email = $_POST['email'];
// Use Prepared Statements to prevent SQL injection
$sql = "INSERT INTO payments (reference, total, full_name, address, phone_number, delivery_type, product_id, email) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssssss", $reference, $total, $fullName, $address, $phoneNumber, $deliveryType, $productId, $email);
// Execute the query
if ($stmt->execute()) {
$response = array('status' => 'success', 'message' => 'Payment details inserted successfully');
} else {
$response = array('status' => 'error', 'message' => 'Error inserting payment details: ' . $stmt->error);
}
// Close the database connection
$stmt->close();
$conn->close();
} else {
$response = array('status' => 'error', 'message' => 'Incomplete POST data');
}
// Send the response back to the JavaScript code
echo json_encode($response);
}
?>
Wrong group
Обсуждают сегодня