Reputation: 1
I have this SQL:
$sql = "INSERT INTO orders (ID, Order_ID, Status, FName, LName, Email,
Phone)VALUES ($UID, $orderID, 'Pending', '$fname', '$lname', '$email',
'$phone');
INSERT INTO orders_inventory (Order_invID, Item_ID, Order_ID, Quantity)
VALUES
(NULL, $item_ID, $orderID, 1);";
This is how I connect it:
if(mysqli_query($db, $sql)){
echo "three";
}
I did an echo on the $sql
and this is what I got:
INSERT INTO orders (ID, Order_ID, Status, FName, LName, Email, Phone)
VALUES (92, 625015841, 'Pending', '1', '1', '1@1', '1');
INSERT INTO orders_inventory (Order_invID, Item_ID, Order_ID, Quantity)
VALUES (NULL, 1, 625015841, 1);
The SQL works when I paste it into the database manually, but the database crashes when I use the website PHP. The $DB
is to connect to the database and it works because I tested it, and I have also been using it throughout the whole website.
I then did an error check using mysqli_error(db)
and I get this error:
"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO orders_inventory (Order_invID, Item_ID, Order_ID, Quantity) VALUES (' at line 2"
Help would be greatly appreciated as I'm very stuck and don't know how to get around this or fix this problem
Upvotes: 0
Views: 474
Reputation: 147166
You're attempting to run two queries at once, which mysqli_query
will not do. However you can use mysqli_multi_query
instead:
if(mysqli_multi_query($db, $sql)){
echo "three";
}
Upvotes: 3