I have a form with multiple text fields of the same name (ingredient[]). My problem is that I can't get the array into the correct format for the insert query to work.
I am trying to keep it simple as I really should allow the user to add more fields as necessary but in the meantime I'm just going to use maybe 10 or 15 ingredient_list fields.
I presume I should be using a foreach loop something along these lines:
Code:
<form action="index.php" method="post">
<fieldset><legend>bla bla:</legend>
<p><b>Ingredients:</b><input type="text" name="ingredient_list[]" /></p>
<p><b>Ingredients:</b><input type="text" name="ingredient_list[]" /></p>
<p><b>Ingredients:</b><input type="text" name="ingredient_list[]" /></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
</form>
I am trying to keep it simple as I really should allow the user to add more fields as necessary but in the meantime I'm just going to use maybe 10 or 15 ingredient_list fields.
I presume I should be using a foreach loop something along these lines:
Code:
foreach ($_POST[$ingredient_list] as $ingredient) {
$query = 'INSERT INTO ingredient_assoc (ingredient_assoc_id, ingredient, recipe_id) VALUES ';
$query .= "($ingredient), ";
$result = @mysql_query ($query);}