wgoldschagg Posted April 20, 2009 Share Posted April 20, 2009 I am trying to create an update database script that loads the existing data and allows the user to update only the fields the user needs to update. I have created 2 files for this purpose (preupdate.php which recalls the existing data and update.php which does the actual apdate). Sofar I can't seem to get the preupdate file to post the changed data - it simply posts whatever it recalled from the database. Please help. Here is my preupdate.php code: <?php include 'src.php'; $id = $_POST['ClientNo']; $result = mysql_query("select * from client where $id like ClientNo"); echo "<Center><table width=\"60%\" border=\"2\" cellpadding=\"2\" cellspacing=\"0\">\n"; echo "<td>\n"; echo "<Center><table width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n"; echo "<tr><td colspan=\"2\"><center><b><Font Size=\"6\"><b><u>Update Details</u></b></font></center></td></tr>\n"; $row = mysql_fetch_array($result); echo "<form name=\"form1\" method=\"post\" action=\"update.php\" style=\"padding:5px;\">\n"; echo "<tr><td style=\"padding:5px;\">Client Number: </td><td><input type=\"hidden\" name=\"ClientNo\" id=\"ClientNo\" value=\"$row[ClientNo]\"></td></tr>\n"; echo "<tr><td style=\"padding:5px;\">Name: </td><td><input type=\"text\" name=\"Name\" id=\"Name\" value=\"$row[Name]\"></td></tr>\n"; echo "<tr><td style=\"padding:5px;\">Surname: </td><td><input type=\"text\" name=\"SName\" id=\"SName\" value=\"$row[sName]\"></td></tr>\n"; echo "<tr><td style=\"padding:5px;\">I.D. Number: </td><td><input type=\"text\" name=\"IDNo\" id=\"IDNo\" value=\"$row[iDNo]\"></td></tr>\n"; echo "<tr><td style=\"padding:5px;\">Telephone Number: </td><td><input type=\"text\" name=\"Tel\" id=\"Tel\" value=\"$row[Tel]\"></td></tr>\n"; echo "<tr><td style=\"padding:5px;\">Fax Number: </td><td><input type=\"text\" name=\"Fax\" id=\"Fax\" value=\"$row[Fax]\"></td></tr>\n"; echo "<tr><td style=\"padding:5px;\">Email Adress: </td><td><input type=\"text\" name=\"Email\" id=\"Email\" value=\"$row\"></td></tr>\n"; echo "<tr><td colspan=\"2\"><center><input type=\"submit\" name=\"submit\" value=\"Update Details\"></center></td></tr>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/154902-help-with-script-please/ Share on other sites More sharing options...
alexweber15 Posted April 20, 2009 Share Posted April 20, 2009 im not sure i get what you mean and also there's no UPDATE queries anywhere in there, so the DB never changes... also, just a quick tip change the WHERE id LIKE xxx to WHERE id = xxx Link to comment https://forums.phpfreaks.com/topic/154902-help-with-script-please/#findComment-814773 Share on other sites More sharing options...
wgoldschagg Posted April 20, 2009 Author Share Posted April 20, 2009 This file(preupdate.php) is meant to recall the existing data and display it in a textfield so the user can edit it. The preupdate.php file currently doesn't post any data that has been changed. It Simply posts what it recalled in the first place. my 2nd file (update.php) code looks like this: <?php if ($_POST['Submit'] == 'Update Details') { if (strlen($_POST['IDNo']) < 16) { die ("Invalid I.D. Number. Please enter a valid I.D. Number."); } include 'src.php'; $ClientNo=$_Post['ClientNo']; $Name=$_Post['Name']; $SName=$_Post['SName']; $IDNo=$_Post['IDNo']; $Tel=$_Post['Tel']; $Fax=$_Post['Fax']; $Email=$_Post['Email']; $AgreeDate=$_Post['AgreeDate']; $UI4In=$_Post['UI4In']; $UI4Date=$_Post['UI4DateI']; $UI19In=$_Post['UI19In']; $UI19Date=$_Post['UI19Date']; $UI27In=$_Post['UI27In']; $UI27Date=$_Post['UI27Date']; $UI23In=$_Post['UI23In']; $UI23Date=$_Post['UI23Date']; $UI28In=$_Post['UI28In']; $UI28Date=$_Post['UI28Date']; $CopyID=$_Post['CopyID']; $CopyIDDate=$_Post['CopyIDDate']; $CopyMar=$_Post['CopyMar']; $CopyMarDate=$_Post['CopyMarDate']; $CopyDev=$_Post['CopyDev']; $CopyDevDate=$_Post['CopyDevDate']; mysql_query("UPDATE client set Name = '$Name', SName = '$SName', IDNo = '$IDNo', Tel = '$Tel', Fax = '$Fax', Email = '$Email', AgreeDate = $AgreeDate', UI4In = '$UI4In', UI4Date = '$UI4Date', UI19In = '$UI19In', UI19Date = '$UI19Date', UI27In = '$UI27In', UI27Date = '$UI27Date', UI23In = '$UI23In', UI23Date = '$UI23Date', UI28In = '$UI28In', UI28Date = '$UI28Date', CopyID = '$CopyID', CopyIDDate = '$CopyIDDate', CopyMar = '$CopyMar', CopyMarDate = '$CopyMarDate', CopyDev = '$CopyDev', CopyDevDate = '$CopyDevDate' Where ClientNo = '$ClientNo'") or die(mysql_error()); echo ("Details Successfully Updated"); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/154902-help-with-script-please/#findComment-814784 Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 Are you getting an error at all? Also, try echoing the post variables to make sure they are what you tink they are. Link to comment https://forums.phpfreaks.com/topic/154902-help-with-script-please/#findComment-814793 Share on other sites More sharing options...
wgoldschagg Posted April 20, 2009 Author Share Posted April 20, 2009 No errors. It goes to update.php, but the the update.php loads a blank page. I think i need a way to display the data recalled in the textfield without actually setting it as a value - I may be wrong. For example: my current code says: echo "<tr><td style=\"padding:5px;\">Name: </td><td><input type=\"text\" name=\"Name\" id=\"Name\" value=\"$row[Name]\"></td></tr>\n"; I think the form posts this value regardless of whether it was edit or not. Link to comment https://forums.phpfreaks.com/topic/154902-help-with-script-please/#findComment-814803 Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 I think you need to turn on error reporting, if you're getting a blank page. Link to comment https://forums.phpfreaks.com/topic/154902-help-with-script-please/#findComment-814815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.