I'm currently working on a database where I would like the order_ID's to be put into two tables. This works but the issue I have is that the loop is only iterating once. If anyone could help and explain where I have gone wrong it would be greatly appreciated.
session_start();
echo $_SESSION['shop_id'];
$shopid = $_SESSION['shop_id'];
$username = $_SESSION['username'];
$con = mysqli_connect('localhost', 'root', '', 'aurora');
if (!isset($con)) {
echo "Connection to Aurora System failed.";
}
if (isset($_POST['items'])) {
echo "True";
} else {
echo "false";
}
$valid = true;
$date = date('l jS \of F Y h:i:s A');
$sql2 = "INSERT INTO orders_new (user_submitted, order_date, customer_ID) VALUES ('$username', '$date', '$shopid')";
if ($valid == true) {
$ordersubmit2 = mysqli_query($con, $sql2);
echo "Success!";
}
$count = $_POST['items'];
for ($i = 1; $i <= $count; $i++) {
$idinsert = mysqli_insert_id($con);
$product = $_POST['product'.$i];
$nicotine = $_POST['nicotine'.$i];
$qty = $_POST['qty'.$i];
echo $product;
$sql = "INSERT INTO orders_detail (orders_id ,product, variant, quantity) VALUES ('$idinsert', '".$product."', '".$nicotine."', '".$qty."')";
$ordersubmit = mysqli_query($con, $sql);
}
$count? justechoit before the loop.root, with or without password, maybe you shouldn't show it to everybody (you could replace them by****in the shown code)