theboyholty Posted November 3, 2008 Share Posted November 3, 2008 I've got a form which is for editing purposes, its shown below. The form fills up with the data for editing and any fields the user changes are successfully changed, but any fields which are NOT altered by the user, are tyhen set to NULL (or no data). Is there anything I can do to retain previously stored data? The form is shown below. <form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST"> <table border="1"><tr><td colspan="2">EDIT RESULT DETAILS</td></tr> <tr><td>MatchID</td><td> <input name="MatchIDedit" value="<?php echo $showdata['MatchID']; ?>" size="5"></td></tr> <tr><td>MatchTypeID</td><td> <input name="MatchTypeID" value="<?php echo $showdata['MatchTypeID']; ?>" size="5"></td></tr> <tr><td>SeasonID</td><td> <input name="SeasonID" value="<?php echo $showdata['SeasonID']; ?>" size="5"></td></tr> <tr><td>MatchNum</td><td> <input name="MatchNum" value="<?php echo $showdata['MatchNum']; ?>" size="5"></td></tr> <tr><td>TeamID</td><td> <input name="TeamID" value="<?php echo $showdata['TeamID']; ?>" size="5"></td></tr> <tr><td>Date</td><td> <input name="Date" value="<?php echo $showdata['Date']; ?>" size="15"></td></tr> <tr><td>Venue</td><td> <input name="Venue" value="<?php echo $showdata['Venue']; ?>" size="6"></td></tr> <tr><td>HT</td><td> <input name="HTGlsSc" value="<?php echo $showdata['HTGlsSc']; ?>" size="2"> <input name="HTGlsConc" value="<?php echo $showdata['HTGlsConc']; ?>" size="2"></td></tr> <tr><td>FT</td><td> <input name="FTGlsSc" value="<?php echo $showdata['FTGlsSc']; ?>" size="2"> <input name="FTGlsConc" value="<?php echo $showdata['FTGlsConc']; ?>" size="2"></td></tr> <tr><td>Result</td><td> <input name="WDL" value="<?php echo $showdata['WDL']; ?>" size="5"></td></tr> <tr><td>Points</td><td> <input name="Points" value="<?php echo $showdata['Points']; ?>" size="3"></td></tr> <tr><td>LgePos</td><td> <input name="LgePos" value="<?php echo $showdata['LgePos']; ?>" size="3"></td></tr> <tr><td>Scorers</td><td> <input name="Scorers" value="<?php echo $showdata['Scorers']; ?>" size="100"></td></tr> <tr><td>Attendance</td><td><input name="Attendance" value="<?php echo $showdata['Attendance']; ?>" size="8"></td></tr> <tr><td colspan="2"><input type="submit" name="submit" value="Submit" /></td></tr> </table> </form> Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/131180-edit-form-nulliifes-any-data-which-is-not-altered/ Share on other sites More sharing options...
JonnoTheDev Posted November 3, 2008 Share Posted November 3, 2008 Build your SQL query up on only fields that contain data: i.e. $sql = array(); if(strlen(trim($_POST['name))) { $sql[] = "name='".$_POST['name']."'"; } if(strlen(trim($_POST['address))) { $sql[] = "address='".$_POST['address']."'"; } if(count($sql)) { $setPart = implode($sql, ","); mysql_query("UPDATE tableName SET ".$setPart." WHERE id='".$_POST['id']."'"); } Quote Link to comment https://forums.phpfreaks.com/topic/131180-edit-form-nulliifes-any-data-which-is-not-altered/#findComment-681058 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.