karenn1 Posted July 4, 2008 Share Posted July 4, 2008 Hey everyone, I have a table that shows records for a specific session ID. I want to give my user the option to update a field for each record. Here's my code: <? $i = 0; while ($rs_grid = pg_fetch_array($result_grid)) { if ($_POST['update']) { // update contents $sql_update = "UPDATE public.waybill SET parcel_contents = '".$_POST['parcel_contents']."', parcel_contents_description = '".$_POST['parcel_contents_description']."' WHERE add_session_id = '".$id."' AND id = '".$rs_grid['id']."' "; $result_update = pg_query($sql_update); } ?> <tr> td align="center" bgcolor="#F5F5F5"><input name="id" type="text" id="id" value="<?= $rs_grid['id']; ?>" size="2" readonly="readonly" /></td> <td align="center" bgcolor="#F5F5F5"><input name="cur_length" type="text" id="cur_length" value="<?= $rs_grid['length']; ?>" size="2" readonly="readonly" /> x <input name="cur_width" type="text" id="cur_width" value="<?= $rs_grid['width']; ?>" size="2" readonly="readonly" /> x <input name="cur_height" type="text" id="cur_height" value="<?= $rs_grid['height']; ?>" size="2" readonly="readonly" /> </td> <td bgcolor="#F5F5F5"><input name="parcel_contents" type="text" id="parcel_contents" size="15" /></td> <td bgcolor="#F5F5F5" class="quote-blue-text"><textarea name="parcel_contents_description" cols="20" id="parcel_contents_description"></textarea></td> </tr> <?php $i++; } ?> With this coding, it's grabbing the value from the last entry each time. I want the value entering into "parcel_contents" and "parcel_contents_description" to be updated to each unique record. I hope that makes sense. Can anybody help? Thanks! Karen Link to comment https://forums.phpfreaks.com/topic/113196-updating-records-in-a-while-loop/ Share on other sites More sharing options...
mmarif4u Posted July 4, 2008 Share Posted July 4, 2008 You are fetching entries from db,then updating in while loop.Are you just fetching one entry. Is this your complete code. Link to comment https://forums.phpfreaks.com/topic/113196-updating-records-in-a-while-loop/#findComment-581587 Share on other sites More sharing options...
karenn1 Posted July 4, 2008 Author Share Posted July 4, 2008 It's not fetching one entry, at this stage I added 3 parcels so the page displays 3 entries. That's what the while loop is fetching. Here's my complete code: <? ini_set('session.cache_limiter', 'private'); session_start(); include("includes/conn.inc.php"); $password = $_SESSION['password']; $sql_member = "SELECT * FROM public.users WHERE password = '".$password."' "; $result_member = pg_query($sql_member); $rs_member = pg_fetch_array($result_member); $sql = "INSERT INTO public.recipient (fname_rec, sname_rec, address1, address2, address3, postalcode, contact_person, homeno, mobileno, email) VALUES ('".$_POST['fname']."', '".$_POST['sname']."', '".$_POST['address1']."', '".$_POST['address2']."', '".$_POST['address3']."', '".$_POST['postalcode']."', '".$_POST['contact_person']."', '".$_POST['homeno']."', '".$_POST['mobileno']."', '".$_POST['email']."' )"; $result = pg_query($sql); $sql2 = "SELECT MAX(id) AS id FROM public.recipient"; $result2 = pg_query($sql2); $rs2 = pg_fetch_array($result2); //echo $rs2['id']; $sql3 = "UPDATE public.waybill SET recipient_detail_id = '".$rs2['id']."' WHERE add_session_id = '".$id."'"; $result3 = pg_query($sql3); $sql_grid = "SELECT * FROM public.waybill WHERE add_session_id = '".$id."'"; $result_grid = pg_query($sql_grid); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/index.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Get a Quote</title> <meta name="keywords" content="cost, collect your parcel, collect, deliver parcel, drop off points, delivery, delivered, get a quote, parcel, pick up point, quote"> <meta name="description" content="get a quote"> <script language="javascript" type="text/javascript" src="scripts/validate.js"></script> <script language="javascript" type="text/javascript" src="scripts/popup.js"></script> <script src="scripts/parcel_validate.js" type="text/javascript"></script> <!-- InstanceEndEditable --> <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> <link href="styles/standby.css" rel="stylesheet" type="text/css" /> <link href="styles/standbyStyles.css" rel="stylesheet" type="text/css" /> <link href="styles/print.css" rel="stylesheet" media="print" type="text/css" /> <script src="scripts/AC_RunActiveContent.js" type="text/javascript"></script> <script type="text/JavaScript"> <!-- function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } //--> </script> </head> <body> <table width="984" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <!--DWLayoutTable--> <tr> <td width="12" rowspan="8" valign="top" background="images/sdw_left.jpg" id="nodisplay"><img src="images/sdw_left.jpg" width="12" height="13" /></td> <td height="180" colspan="7" valign="top"><script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','960','height','180','src','../flash/standby_header','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','../flash/standby_header' ); //end AC code </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="960" height="180"> <param name="movie" value="flash/standby_header.swf" /> <param name="quality" value="high" /> <embed src="flash/standby_header.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="960" height="180"></embed> </object></noscript></td> <td width="12" rowspan="8" valign="top" background="images/sdw_right.jpg" id="nodisplay"><img src="images/sdw_right.jpg" width="12" height="13" /></td> </tr> <tr> <td height="10" colspan="7" valign="top" background="images/header_bot_smudge.gif"><img src="images/header_bot_smudge.gif" width="20" height="10" /></td> </tr> <tr> <td width="12" rowspan="6" valign="top" bgcolor="#FFFFFF" id="nodisplay"><!--DWLayoutEmptyCell--> </td> <td height="10" colspan="5" valign="top" bgcolor="#FFFFFF"><img src="images/transparency.gif" width="20" height="10" /></td> <td width="12" rowspan="6" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td> </tr> <tr> <td height="60" colspan="5" valign="top" bgcolor="#FFFFFF"> <div align="left"> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','936','height','60','src','../flash/text_scroll_top','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','../flash/text_scroll_top' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="936" height="60"> <param name="movie" value="flash/text_scroll_top.swf" /> <param name="quality" value="high" /> <embed src="flash/text_scroll_top.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="936" height="60"></embed> </object> </noscript> </div></td> </tr> <tr> <td height="12" colspan="5" valign="top" bgcolor="#FFFFFF"><img src="images/transparency.gif" width="20" height="12" /></td> </tr> <tr> <td width="180" height="1260" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="180" height="319" valign="top" bgcolor="#F5F5F5"><script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','180','height','300','src','../flash/side_left_1','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','../flash/side_left_1' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="180" height="300"> <param name="movie" value="flash/side_left_1.swf" /> <param name="quality" value="high" /> <embed src="flash/side_left_1.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="180" height="300"></embed> </object></noscript></td></tr> <tr> <td height="209" valign="top" bgcolor="#FFFFFF"><script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','180','height','190','src','../flash/side_left2','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','../flash/side_left2' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="180" height="190"> <param name="movie" value="flash/side_left2.swf" /> <param name="quality" value="high" /> <embed src="flash/side_left2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="180" height="190"></embed> </object> </noscript></td> </tr> <tr> <td height="319" valign="top" bgcolor="#FFFFFF"><script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','180','height','300','src','../flash/side_left_3','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','../flash/side_left_3' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="180" height="300"> <param name="movie" value="flash/side_left_3.swf" /> <param name="quality" value="high" /> <embed src="flash/side_left_3.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="180" height="300"></embed> </object> </noscript></td> </tr> <tr> <td height="186"></td> </tr> </table></td> <td width="9" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td> <td width="557" valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="561" height="866" valign="top"><!-- InstanceBeginEditable name="body-text" --> <p><br /> <a href="parcels1.php"><img src="images/title_get_a_quote.gif" width="147" height="26" border="0" /></a></p> <form name="form" method="post" action="multipleparcels7.php" onSubmit="return validate_form();"> <table width="535" height="208" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#E8E8E8"> <tr> <td width="77" height="29" class="form-small-text"><div align="center">Shipping Details </div></td> <td width="77" class="form-small-text"><div align="center">Services</div></td> <td width="77" class="form-small-text"><div align="center">Terms & Conditions </div></td> <td width="154" class="form-small-text"><div align="center">Address Details </div></td> <td width="80" class="form-small-text"><div align="center">Contents & <br /> Cover </div></td> <td width="77" class="form-small-text"><div align="center">Quote & <br /> Payment</div></td> </tr> <tr> <td colspan="6" class="textBlueBold"><img src="images/steps6.gif" width="542" height="25" /></td> </tr> <tr> <td height="151" colspan="6" class="quote_table_bg"><table width="523" height="230" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td width="247" height="25"> </td> <td width="1"> </td> <td width="257"> </td> </tr> <tr> <td height="22" colspan="3" class="textBlueBold">Parcel Details: </td> </tr> <tr> <td height="25"> </td> <td> </td> <td> </td> </tr> <tr> <td height="28" colspan="3" class="quote-blue-text"><table width="511" height="89" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#EBEBEB"> <tr> <td align="center" bgcolor="#DDDDDD" class="quote-blue-text"><strong>ID</strong></td> <td height="26" align="center" bgcolor="#DDDDDD" class="quote-blue-text"><strong>length x width x height</strong></td> <td width="104" bgcolor="#DDDDDD" class="quote-blue-text"><strong>Contents</strong></td> <td width="116" bgcolor="#DDDDDD" class="quote-blue-text"><strong>Description</strong></td> </tr> <? $i = 0; while ($rs_grid = pg_fetch_array($result_grid)) { if ($_POST['update']) { // update contents $sql_update = "UPDATE public.waybill SET parcel_contents = '".$_POST['parcel_contents']."', parcel_contents_description = '".$_POST['parcel_contents_description']."' WHERE add_session_id = '".$id."' AND id = '".$rs_grid['id']."' "; $result_update = pg_query($sql_update); } ?> <tr> <td align="center" bgcolor="#F5F5F5"><input name="id" type="text" id="id" value="<?= $rs_grid['id']; ?>" size="2" readonly="readonly" /></td> <td align="center" bgcolor="#F5F5F5"><input name="cur_length" type="text" id="cur_length" value="<?= $rs_grid['length']; ?>" size="2" readonly="readonly" /> x <input name="cur_width" type="text" id="cur_width" value="<?= $rs_grid['width']; ?>" size="2" readonly="readonly" /> x <input name="cur_height" type="text" id="cur_height" value="<?= $rs_grid['height']; ?>" size="2" readonly="readonly" /> </td> <td bgcolor="#F5F5F5"><input name="parcel_contents" type="text" id="parcel_contents" size="15" /></td> <td bgcolor="#F5F5F5" class="quote-blue-text"><textarea name="parcel_contents_description" cols="20" id="parcel_contents_description"></textarea></td> </tr> <?php $i++; } ?> <tr> <td align="center" bgcolor="#F5F5F5" class="quote-blue-text"> </td> <td align="center" bgcolor="#F5F5F5" class="quote-blue-text"> </td> <td colspan="2" align="center" bgcolor="#F5F5F5"><div align="right"> <input name="update" type="submit" class="bodyTextNormal-nolineheight" id="update" value="Update" /> </div></td> </tr> <tr> <td colspan="4" align="center" bgcolor="#F5F5F5"></td> </tr> </table></td> </tr> <tr> <td height="25" class="quote-blue-text"> </td> <td class="body-text-nopadding"> </td> <td class="body-text-nopadding"> </td> </tr> <tr> <td height="25" class="quote-blue-text"><div align="right">Would you like to purchase cover for your parcel? </div></td> <td class="body-text-nopadding"> </td> <td class="body-text-nopadding"><select name="insurance" class="bodyTextNormal" id="insurance"> <option value="0" selected="selected">No cover</option> <option value="15">Up to R750.00 = R15.00</option> <option value="30">Up to R1500.00 = R30.00</option> <option value="40">Up to R2000.00 =R40.00</option> </select> </td> </tr> <tr> <td height="25" class="quote-blue-text"> </td> <td class="body-text-nopadding"> </td> <td class="body-text-nopadding"> </td> </tr> <tr> <td height="25" colspan="3" class="quote-blue-text"><p><strong>Please note</strong>: Print and complete the <strong><U><a href="files/inventory_list.pdf" target="_blank">inventory form</a></U></strong> for any parcel with personal items. If the <strong><U><a href="files/inventory_list.pdf" target="_blank">inventory form</a></U></strong> is not complete your parcel will not be accepted for final shipment.</p></td> </tr> <tr> <td height="30" class="body-text-nopadding"> </td> <td class="body-text-nopadding"> </td> <td class="body-text-nopadding"><div align="right"> <input name="Submit2" type="submit" class="bodyTextNormal" id="Submit2" value="Get your Quote >>"/> </div></td> </tr> </table> </td> </tr> <tr> <td height="17" colspan="6"><img src="images/steps1_r3_c1.gif" width="542" height="17" /></td> </tr> </table> </form> <!-- InstanceEndEditable --></td> </tr> <tr> <td height="167"></td> </tr> <!--DWLayoutTable--> </table></td> <td width="10" valign="top" bgcolor="#FFFFFF" id="nodisplay"><!--DWLayoutEmptyCell--> </td> <td width="180" valign="top" bgcolor="#FFFFFF" id="nodisplay"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="180" height="337" valign="top"><p> <? if ($_SESSION['authorization'] == 'member') { ?> </p> <p class="titleSubTitleBlueOne">Member Area<br /> <span class="bodyTextNormal">Welcome <?= $rs_member['fname']; ?> ! You are now logged in. </span> </p> <p><span class="bodyTextNormal"><a href="../<?= $_SESSION['authorization'] ?>/index.php"> <?= ucwords($_SESSION['authorization']); ?> Home</a></span><br /> <span class="bodyTextNormal"><a href="../<?= $_SESSION['authorization'] ?>/logout.php">Logout</a></span></p> <p> <? } else if ($_SESSION['authorization'] == 'admin') { ?> <span class="titleSubTitleBlueOne">Admin Area</span><br /> <span class="bodyTextNormal">Welcome <?= $rs_member['fname']; ?> ! You are now logged in. </span> </p> <p><span class="bodyTextNormal"><a href="../<?= $_SESSION['authorization'] ?>/index.php"> <?= ucwords($_SESSION['authorization']); ?> Home</a></span><br /> <span class="bodyTextNormal"><a href="../<?= $_SESSION['authorization'] ?>/logout.php">Logout</a></span></p> <p> <? } else if ($_SESSION['authorization'] == 'depot') { ?> <span class="titleSubTitleBlueOne">Depot Area</span><br /> <span class="bodyTextNormal">Welcome <?= $rs_member['fname']; ?> ! You are now logged in. </span> </p> <p><span class="bodyTextNormal"><a href="../<?= $_SESSION['authorization'] ?>/index.php"> <?= ucwords($_SESSION['authorization']); ?> Home</a></span><br /> <span class="bodyTextNormal"><a href="../<?= $_SESSION['authorization'] ?>/logout.php">Logout</a></span></p> <p> <? } else { ?> </p> <p><span class="titleSubTitleBlueOne">User Login</span><br /> <span class="bodyTextNormal">Enter your details below to log in. Please note that these fields are case sensitive:</span><br /> <br /> <?php if(isset($_REQUEST['failed'])) { if ($_REQUEST['failed'] == "invalid") { print "<div><font face='arial' size='1' color='red'><strong>Login Failed - Please try again</strong></font></div><br>"; } elseif ($_REQUEST['failed'] == "inactive") { print "<div><font face='arial' size='1' color='red'><strong>Your account is currently disabled<br>Please contact management</strong></font></div><br>"; } elseif ($_REQUEST['failed'] == "ip") { print "<div><font face='arial' size='1' color='red'><strong>Your account is currently disabled due to possible 3<sup>rd</sup> party abuse. Please contact management</strong></font></div><br>"; } } ?> </p> <form action="index.php" method="post" name="form1" id="form1"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td class="bodyTextNormal">Username</td> <td> <input name="username" type="text" size="15" /></td> </tr> <tr> <td class="bodyTextNormal">Password</td> <td> <input name="password" type="password" size="15" /></td> </tr> <tr> <td> </td> <td align="right"><br /> <input name="Submit" type="submit" class="bodyTextNormal" value="Submit" /></td> </tr> </table> </form> <p class="bodyTextNormal">New user? <a href="register_intro.php">Click here to register. </a></p> <p> <? } ?> </p> <p> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','180','height','318','src','../flash/side_right_1','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','../flash/side_right_1' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="180" height="318"> <param name="movie" value="flash/side_right_1.swf" /> <param name="quality" value="high" /> <embed src="flash/side_right_1.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="180" height="318"></embed> </object> </noscript> <br /> </p></td> </tr> <tr> <td height="23"> </td> </tr> <tr> <td height="224" valign="top"><script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','180','height','190','src','../flash/side_right2','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','../flash/side_right2' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="180" height="190"> <param name="movie" value="flash/side_right2.swf" /> <param name="quality" value="high" /> <embed src="flash/side_right2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="180" height="190"></embed> </object> </noscript></td> </tr> <!--DWLayoutTable--> </table></td> </tr> <tr> <td height="60" colspan="5" valign="top"><img src="images/footer.jpg" width="936" height="60" /></td> </tr> <tr> <td height="12" colspan="5" valign="top"><img src="images/transparency.gif" width="20" height="12" /></td> </tr> </table> </body> <!-- InstanceEnd --></html> Does any of this make sense? Karen Link to comment https://forums.phpfreaks.com/topic/113196-updating-records-in-a-while-loop/#findComment-581605 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.