Sindbad~EG File Manager
<?php
include ('conn.php');
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Retrieve and sanitize input data
$name = htmlspecialchars($_POST['name']);
$pincode = htmlspecialchars($_POST['pincode']);
$address = htmlspecialchars($_POST['address']);
$contact = htmlspecialchars($_POST['contact']);
$itemDetails = json_decode($_POST['itemDetails'], true); // Decode JSON string into PHP array
// Encode itemDetails before inserting into the database
$itemDetailsEncoded = json_encode($itemDetails);
// Prepare SQL statement
$sql = "INSERT INTO orders (name, pincode, address, contact, item_details, order_date)
VALUES (?, ?, ?, ?, ?, NOW())";
$stmt = $conn->prepare($sql);
// Bind parameters and execute statement
$stmt->bind_param("sssss", $name, $pincode, $address, $contact, $itemDetailsEncoded);
$stmt->execute();
// Check if insertion was successful
if ($stmt->affected_rows > 0) {
$order_id = $stmt->insert_id; // Get the ID of the inserted order
$stmt->close();
$conn->close();
// Redirect to order status page with success message
header("Location: order-status.php?success=true&order_id=$order_id");
exit();
} else {
$response = ['success' => false, 'message' => 'Failed to process order. Please try again.'];
}
// Close statement
$stmt->close();
} else {
$response = ['success' => false, 'message' => 'Invalid request method.'];
}
// Close connection
$conn->close();
// Respond with JSON indicating success or failure
echo json_encode($response);
exit;
?>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists