I have a form with data I will like to insert in 2 different tables (order and order_etails). Here is what I did. But it is inserting in only 1 form.
<?php
include '../db/connect.php';
$sql="INSERT INTO order_etails (part_id, quantity, price, status_id,order_id)
VALUES
('$_POST[part_id]','$_POST[quantity]','$_POST[price]','$_POST[status_id]','$_POST[order_id] '),
('$_POST[part_id2]','$_POST[quantity2]','$_POST[price2]','$_POST[status_id2]','$_POST[order _id2]'),
('$_POST[part_id3]','$_POST[quantity3]','$_POST[price3]','$_POST[status_id3]','$_POST[order _id3]')";
$sql1="INSERT INTO order (platform)
VALUE
('$_POST[platform]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "record(s) added";
mysqli_close($con);
?>
I have also tried this:
<?php
include '../db/connect.php';
$sql="INSERT INTO order_details (part_id, quantity, price, status_id,order_id)
VALUES
('$_POST[part_id]','$_POST[quantity]','$_POST[price]','$_POST[status_id]','$_POST[order_id]'),
('$_POST[part_id2]','$_POST[quantity2]','$_POST[price2]','$_POST[status_id2]','$_POST[order_id2]'),
('$_POST[part_id3]','$_POST[quantity3]','$_POST[price3]','$_POST[status_id3]','$_POST[order_id3]');
INSERT INTO order (platform)
VALUE
('$_POST[platform]')";
mysql_query($sql1);
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "record(s) added";
mysqli_close($con);
?>
$sqland not$sql1$_POSTdata directly in a query. You must use proper escaping to avoid serious SQL injection bugs. It's not clear why you're mixingmysql_queryandmysqliasmysqlihas thebind_parammethod that neatly avoids all of this mess.