When sending the data to complete order, only the data is inserted in the first table order
but in the table order_details
does not record data.
And it is addressed to /index.php?a=orderfail
The structure of my table is as follows:
order
id_order id_product id_user status
1 3 2 complete
order_details
id_order_product id_product quantity price id_order
1 3 1 10.00 1
My code: updateorder.php
session_start();
require "conexion.php";
$formid = isset($_SESSION['formid']) ? $_SESSION['formid'] : "";
if ($formid != $_POST['formid']) {
echo "E00001 !! ERROR DE SESIÓN REINTENTAR OTRA VEZ.";
} else {
unset($_SESSION['formid']);
if ($_POST) {
$id_product = $_POST['id_product '];
$id_user = $_POST['id_user'];
$status = $_POST['status'];
$stmt = $con->prepare("INSERT INTO order ('id_product', 'id_user', 'status') VALUES (?, ?, ?) ");
$stmt->bind_param('iis', $id_product,$id_user,$status);
$stmt->execute();
if ($stmt->fetch()) {
$order_id = $stmt->insert_id;
for ($i = 0; $i < count($_POST['qty']); $i++) {
$quantity = $_POST['qty'][$i];
$price = $_POST['price'][$i];
$id_product = $_POST['id_product'][$i];
$stmt = $con->prepare("INSERT INTO order_details ('id_product', 'quantity', 'price', 'id_order') VALUES (?, ?, ?, ?) ");
$stmt->bind_param('iisi', $id_product,$quantity,$price,$order_id);
$stmt->execute();
}
unset($_SESSION['cart']);
unset($_SESSION['qty']);
header('location:index.php?a=order');
}else{
$stmt->close();
header('location:index.php?a=orderfail');
}
}
}