I’m creating a script to add recipes to a database. For my add_recipe form, I’d like to give users an option to add as many ingredients as they’d like.
The following code is just something I came up with for testing purposes, since I’ve never tried this before:
<?php
$ingredient = '(another ingredient)';
$num_ingredients = $_REQUEST['select'];
?>
<html>
<form name="form1" method="post" action="onchange.php">
<select name="select" onchange="javascript: document.form1.submit();">
<option value=1>Add 1 Ingredient</option>
<option value=2>Add 2 Ingredients</option>
<option value=3>Add 3 Ingredients</option>
</select>
</form>
</body>
</html>
<?php
while ($num_ingredients <= 3) {
$num_ingredients++;
echo $ingredient;
echo '<br />';
}
?>
The problem is…my code, lol. For example…
option value=1 returns:
(another ingredient)
(another ingredient)
option value=3 returns:
(another ingredient)
Can someone steer me in the right direction? Any help is greaaaatly appreciated 8)
You need a counter variable.