hmark Posted January 29, 2010 Share Posted January 29, 2010 I'm having some trouble...here's my dilenma. I'm allowing my user to query the database based on a "pack code". It then displays the pack code and other information about this "pack code". I'm able to let users edit the other information with no trouble. But now, I'm wanting to change my code to allow them to also chance the "pack code" field if it's incorrect. Here my php codes (two parts php_edit2.php and php_edit3.php): [code=php:0]? require 'lib-hollydb.inc'; connect_to_db("$dbname"); $pcode = $_GET['pcode']; $q = "select * from hollydb.experts where pcode='$pcode'"; connect_to_db("$dbname"); $res = run_query($q); $rec = mysql_fetch_array($res); if(!$rec){ errorMsg(" No record found. Please try again."); } ?> <? cePageHead(); ceLeftMenu(); ?> <td> <b>PRO input:</b> <a href="pred_input.php">add</a> | edit | <a href="pred_delete.php">delete</a> <br> <BR> Edit a record<br><br> <form action="pred_edit3.php"> <input type="hidden" name="pcode" value=<?echo "$pcode"?>> <table> <tr> <td>Code:</td> <td><input type="text" name="pcode" value="<?echo $rec['pcode']?>"><td> </tr> <tr> <td>Comcode:</td> <td><input type="text" name="comcode" value="<?echo $rec['comcode']?>"><td> </tr> <tr> <td>Description:</td> <td><input type="text" name="descript" value="<?echo $rec['descript']?>"><td> </tr> <tr> <td> </td> <td><br><input type="submit" value="save"><td> </tr> </table> </form> </body> </html> [/code] [code=php:0]<? require 'lib-hollydb.inc'; $pcode=$_GET['pcode']; $ay = array_keys($_GET); $x = implode(",",$ay); $y = implode("','", $_GET); $a = array(); foreach ($_GET as $key => $value) { if($value != ''){ $q = "$key='$value'"; array_push($a,$q); } } $q = implode(", ",$a); $q = "update experts set $q where pcode='$pcode'"; connect_to_db("$dbname"); run_query($q); ?> <? cePageHead(); ceLeftMenu(); ?> <b> Thank you. <br> Pack/Product Code: <?echo $pcode?> has been updated. </b> </td> </tr> <br> </td> </tr> </table> </div> </body> </html> [/code] Is there an easy way to modify this? Or should i just allow users to delete record and re-enter the data. This is not preferred, but i can do that if it's easier. Thank you Link to comment https://forums.phpfreaks.com/topic/190246-editing-field-that-user-is-querying-on/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.