Jump to content

Updating SQL from many fields


gerkintrigg

Recommended Posts

Hiya.

I'm making a shopping cart system with admin back end to change categories. I'm trying to allow multiple categories to be ammended at the same time using a loop like this:
[code]$cat_sql=mysql_query("SELECT category FROM Categories ORDER BY category");
while ($cat_loop=mysql_fetch_array($cat_sql)){
echo '<tr bgcolor="#FFFFFF">
                    <td width="133" class="text" valign="top"><a href="index.php?mcat='.$cat_loop['category'].'">'.$cat_loop['category'].'</a><br>
                    </td>
                    <td width="12">&nbsp;</td>
                    <td width="145" valign="top"><input name="'.$cat_loop['id'].'" type="text" class="search" value="'.$cat_loop['category'].'">
                        <input name="id" type="hidden" id="mcat" value="'.$cat_loop['id'].'">                      </td>
                  </tr>';
}[/code]
My question is, once submitted, how do I loop through all these fields and update each one? I understand the SQL and I think the PHP is something like foreach($_POST[]){ but that's clearly not right.

Could anyone help me please?
Link to comment
https://forums.phpfreaks.com/topic/15876-updating-sql-from-many-fields/
Share on other sites

If you want to get informations from the form submited, use $_POST['[b]form-name[/b]'].
Example:
[code]<input name="'.$cat_loop['id'].'" type="text" class="search" value="'.$cat_loop['category'].'">[/code]
Change it to something like
<input name="search" type="text" class="search" value="'.$cat_loop['category'].'">
So it will be $_POST['search'] hope this is what you looking for.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.