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
https://forums.phpfreaks.com/topic/251524-loop-within-a-form-to-sql/
Share on other sites

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.