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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.