Jump to content

Loop Within a Form to SQL


savagenoob

Recommended Posts

OK, I am displaying text fields from entries in a database, and want to update all the fields within the loop if the user hits Update.

 

<table class="tablesorter">
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input type="hidden" value="<?php echo $agencyid; ?>" name="agencyid" />
<tr><h2>Appointments</h2></tr>
<?php
$select = mysql_query("SELECT * FROM appointment WHERE agencyid = '$agencyid'")or die(mysql_error());
while($appinfo = mysql_fetch_array($select)){
?>
<input type="hidden" value="<?php echo $appinfo['ID']; ?>" name="<?php echo $appinfo['ID']; ?>" />
<tr>
<th>Carrier: </th><td><?php echo $appinfo['carrier'];?></td><th>Agency Code: </th><th><input type="text" value="<?php echo $appinfo['agentcode'];?>" size="15" maxlength="20" name="agencycode<?php echo $appinfo['ID']; ?>" tabindex="1" /></th>
</tr>
<?php
}
?>
<tr><th><input type="submit" value="Update" name="updateapp" tabindex="2" /></th></tr>
</form>
</table>

 

I cant figure out an easy way to build a query off of the data once its submitted. Maybe a foreach loop on the POST then update as necessary? I cant wrap my mind around it.

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.