Wenn ich dies in MySql Konsole einfügenMySql Transaktion funktioniert nur in der Konsole
START TRANSACTION;
INSERT INTO `orders` (customer_id) VALUES ('2');
SET @lastid=LAST_INSERT_ID();
INSERT INTO `transactions`
(order_id,product_id,product_quantity,price,ammount,customer_id)
VALUES (@lastid,'3','2','4','4','2');
INSERT INTO `transactions`
(order_id,product_id,product_quantity,price,ammount,customer_id)
VALUES (@lastid,'1','3','5','4','2');
COMMIT;
es funktioniert gut, wenn ich versuche, das gleiche über PHP zu tun
$sql = "START TRANSACTION;";
$sql .="INSERT INTO `orders` (customer_id) VALUES ('$customer_id_form');";
$sql .="SET @lastid=LAST_INSERT_ID();";
foreach ($product_id_form as $key => $product){
$sql .= "INSERT INTO `transactions`
(order_id,product_id,product_quantity,price,ammount,customer_id)
VALUES
(@lastid,'$product','$quantity_form[$key]',
'$price_form[$key]','$amount_form[$key]','$customer_id_form');";
}
$sql .= "COMMIT;";
//$sql = "INSERT INTO products (`product_name`,`curent_price`,`product_quota`) VALUES ('$productname_form','$productprice_form','$productquote_form')";
if ($con->query($sql) === TRUE) {
echo "New record created successfully";
header("Location: order.php");
} else {
echo "Error: " . $sql . "<br>" . $con->error;
}
mysqli_close($con);
es nicht Fehler funktioniert gezeigt wird
Sie haben einen Fehler in Ihrer SQL-Syntax; das Handbuch, dass auf Ihre MariaDB Server-Version für die richtige Syntax 'INSERT INTO
orders
(customer_id) VALUES verwendet in der Nähe (' 2 ') entspricht; SET @ lastid = LAST_INSERT_ID(); IN' at line 1