PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<form action="inc/frm.php?f=pro_add" method="post">
<table>
<? for ($i=1; $i<=10; $i++){ ?>
<tr>
<td>
<!-- I make a list of products from a mysql db -->
<select id="cat_id" name="cat_id<? echo $i; ?>">
<? while ($pro4_fa = mysql_fetch_assoc($pro4)){ ?>
<option value="<? echo $pro4_fa['cat_id']; ?>"><? echo $pro4_fa['cat_name']; ?></option>
<? } ?>
</select>
<? mysql_data_seek($pro4,0); ?>
</td>
<td><input type="text" class="w95" id="pro_model" name="pro_model<? echo $i; ?>" /></td>
<td><input type="text" class="w95" id="pro_descrip" name="pro_descrip<? echo $i; ?>" /></td>
<td>$ <input type="text" class="w80" id="pro_sell" name="pro_sell<? echo $i; ?>" /></td>
<td class="c"><input type="checkbox" id="tax_id" name="tax_id<? echo $i; ?>" value="1" checked="checked" /></td>
</tr>
<? } ?>
</table>
<input type="submit" value="Save Products" />
</form>
I need to post each of these 10 sections but I don't know how and I have been trying for literally hours with foreach, for and now I'm down to making it static just for the time being. I haven't encountered something like this before so if you can help please let me know!
Well as long as the select input is named the same as the field in the database the following should work. Also a much better way would be to make one long query rather than a lot of small queries and then insert it but quite frankly I can't be bothered to code that out, but this should work.
foreach($_POST as $field => $value) {
mysql_query("INSERT INTO table ('".$field."') VALUES ('".$value."')");
}
[/syntax]
foreach was a farily new concept for me because the need had never come up before, but I actually found an example almost exactly like yours but each field was:
foreach was a farily new concept for me because the need had never come up before, but I actually found an example almost exactly like yours but each field was: