My UPDATE script just doesn't work. I just couldn't find what was wrong, every variable is declared. Please find what's wrong with my code. Thanks.
***THIS IS THE CODE FROM WHERE THE EDITING WILL TAKE PLACE***
***THIS IS THE UPDATE PROCESSING CODE***
***THIS IS THE CODE FROM WHERE THE EDITING WILL TAKE PLACE***
Code:
<?php require_once("includes/db_connect.php"); ?> <?php require_once("includes/functions.php"); ?> <?php $equipid = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipid']))); //EquipID variable $query = "SELECT * FROM tblequipmentmasterlist "; $query .= "WHERE equipid =" . $equipid; $query .= " LIMIT 1"; $query_result = mysqli_query($db_cxn, $query); while ($row = mysqli_fetch_array ($query_result)) { //Variables to be used to output on the textfields $equipname = $row['equipname']; $manufacturer = $row['manufacturer']; $serno = $row['serno']; $modelno = $row['modelno']; $capacity = $row['capacity']; $curloc = $row['curlocation']; $equipcode = $row['equipcode']; $seqno = $row['seqno']; $adddate = $row['adddate']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>EST-Equipment Intranet-Calibration-Update Equipment Record</title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" /> <style type="text/css"> <!-- .style1 { color: #000000; font-size: medium; } #wrap #content .right .newequipment { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-weight: lighter; text-transform: capitalize; text-align: left; text-indent: 5px; margin: 10px; padding: 10px; width: 350px; } --> </style> <?php include("includes/calheader.php"); ?> <h2>Update Equipment Information Form</h2> <form action = "processform_update.php" method = "POST"> <div class="DataInput"> <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname6"> <tr> <td width="200" class="style1">Equipment ID No.</td> <td width="507"><input name="equipid" type="text" id="equipid" tabindex="" value="<?php echo $equipid; ?>" size="7" /> </tr> </table> </div> <div class="DataInput"> <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname"> <tr> <td width="200" class="style1">Equipment Name</td> <td width="507"> <input name="equipname" type="text" id="equipname" tabindex="1" value="<?php echo $equipname; ?>" size="40" /> </td> </tr> </table> </div> <div class="DataInput"> <table width="708" border="0" cellpadding="0" cellspacing="0" id="Equipname2"> <tr> <td width="200" class="style1">Manufacturer</td> <td width="508"> <input name="manufacturer" type="text" id="manufacturer" tabindex="2" value="<?php echo $manufacturer; ?>" size="40" /> </td> </tr> </table> </div> <div class="DataInput"> <table width="561" border="0" cellpadding="0" cellspacing="0" id="Equipname3"> <tr> <td width="200" class="style1">Serial No. (if any)</td> <td width="361"> <input name="serno" type="text" id="serno" tabindex="3" value="<?php echo $serno; ?>" size="30" /> </td> </tr> </table> </div> <div class="DataInput"> <table width="561" border="0" cellpadding="0" cellspacing="0" id="Equipname4"> <tr> <td width="200" class="style1">Model No. (if any)</td> <td width="361"> <input name="modelno" type="text" id="modelno" tabindex="4" value="<?php echo $modelno; ?>" size="30" /> </td> </tr> </table> </div> <div class="DataInput"> <label class="style6"></label> <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname5"> <tr> <td width="200" class="style1">Capacity / Range</td> <td width="507"> <input name="capacity" type="text" id="capacity" tabindex="5" value="<?php echo $capacity; ?>" size="40" /> </td> </tr> </table> </div> <div class="DataInput"> <label class="style6"></label> <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname6"> <tr> <td width="200" class="style1">Current Location</td> <td width="507"> <input name="curlocation" type="text" id="curlocation" value="<?php echo $curloc; ?>" tabindex="6" size="20" /> <a href='locationcode.php' target='_blank' class='style7'>...Click here for definition...</a> </td> </tr> </table> </div> <div class="DataInput"> <label class="style6"></label> <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname5"> <tr> <td width="200" class="style1">Equipment Code</td> <td width="507"> <input name="equipcode" type="text" id="equipcode" value="<?php echo $equipcode; ?>" tabindex="7" size="20" /> <a href='equipmentcode.php' target='_blank' class='style7'>...Click here for definition...</a> </td> </tr> </table> </div> <div class="DataInput"> <table width="561" border="0" cellpadding="0" cellspacing="0" id="Equipname8"> <tr> <td width="200" class="style1">Sequence Number</td> <td width="361"> <input name="seqno" type="text" id="seqno" tabindex="8" size="7" maxlength="7" value="<?php echo $seqno; ?>" /> </td> </tr> </table> </div> <div class="DataInput"> <label class="style6"></label> <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname5"> <tr> <td width="200" class="style1">Date Added</td> <td width="507"> <input name="adddate" type="text" id="adddate" tabindex="9" value="<?php echo $adddate; ?>" size="20" /> <strong>YYYY-MM-DD</strong> </td> </tr> </table> </div> <p> </p> <div class="DataInput"> <input type="submit" name="submit" id="submit" value="Submit" /> </div> </form> <p><br /> <br /> <br /> <br /> <br /> </div> <?php require("includes/footer.php"); ?>
Code:
<?php include("includes/db_connect.php"); ?> <?php require_once("includes/functions.php"); ?> <?php $equipid = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipid']))); $equipname = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['equipname']))); $manufacturer = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['manufacturer']))); $serno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['serno']))); $modelno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['modelno']))); $capacity = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['capacity']))); $curloc = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['curlocation']))); $equipcode = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipcode']))); $seqno = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['seqno']))); $addDate = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['adddate']))); $query_update = "UPDATE tblequipmentmasterlist SET "; $query_update .= "equipname = '{$equipname}', "; $query_update .= "manufacturer = '{$manufacturer}', "; $query_update .= "serno = '{$serno}', "; $query_update .= "modelno = '{$modelno}', "; $query_update .= "capacity = '{$capacity}', "; $query_update .= "curlocation = '{$curloc}', "; $query_update .= "equipcode = '{$equipcode}', "; $query_update .= "seqno = '{$seqno}', "; $query_update .= "adddate = '{$addDate}' "; $query_update .= "WHERE 'tblequipmentmasterlist'.'equipid' = {$equipid} LIMIT 1"; if (mysqli_affected_rows() == 1) { header ("LOCATION : updatedata.php"); } else { print_r($_POST); var_dump($_POST); echo "<p>Update failed : <br />". $query_update. " <br/>Please contact the site administrator.</p>"; echo "<p>" . mysqli_error($db_cxn) . "</p>"; } ?> <?php if (isset($db_cxn)) { mysqli_close($db_cxn); } ?>
Comment