savagenoob Posted November 21, 2011 Share Posted November 21, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251524-loop-within-a-form-to-sql/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.