I have a couple of arrays of values. I would like to insert them into a table one row at a time using a loop. I am able to insert the correct number of rows, but the values are not inserting properly.
For example, $ingredient_general
is an array that has posted to this page. Assume it has 3 values. I want the value at position 0 to insert first, then on the next loop at position 1, and then then next row gets the value at position 2. Each of the three top variables are all arrays with the same number of values in each.
I tried doing $ingredient_general['.$i.']
in values part of the query in the loop but all it did was put "$ingredient_general[0]"
into the table and not the value that this represents.
$ingredient_general = $_POST['ingredient_general'];
$ingredient_amount = $_POST['ingredient_amount'];
$ingredient_image = $_POST['ingredient_image'];
$recipe_ID = $_POST['recipe_ID'];
print_r($ingredient_general);
//$name = $ingredient_general.$ingredient_amount;
$c = count($ingredient_general);
for ($i = 0; $i <= $c; $i++) {
$addIngredientQuery = "INSERT INTO `ingredients` (recipe_ID,general_name, image) VALUES ('$recipe_ID', '$ingredient_general', '$ingredient_image')";
mysqli_query($con, $addIngredientQuery);
$i++;
}