So I have a form with 4 array inputs. When I hit submit it only submits the first array values. ID is the current session holder to make sure that it creates multiple rows with the same ID. I'm trying to have it loop through and insert multiple products under the same ID. Any ideas?
session_start();
$conn = new mysqli("$server", "$user_name", "$password", "$database");
$productName = $_POST['productName'];
$productPrice = $_POST['productPrice'];
$productDescription = $_POST['productDescription'];
$productImage = $_POST['productImage'];
$id = $_SESSION['id'];
$productNameCount = count($productName);
if (isset($productName) && isset($productPrice) && isset($productDescription) && isset($productImage)) {
for ($i = 0; $i < $productNameCount; $i++) {
$productNumber = $i + 1;
$sql .= "INSERT INTO Products (id, productNumber, productName, productPrice, productDescription, productImage)
VALUES ('$id', '$productNumber', '$productName[$i]', '$productPrice[$i]',
'$productDescription[$i]', '$productImage[$i]');";
}
$conn->query($sql);
}
mysqli_close($conn);