By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Error Handling If A Record Is Not Found

P: 22
I would like to kindly seek some coding assistance. I would like to put some kind of error handling in my code if, say, an ID number was entered, but that ID number has no existing record in the database. I have entered some kind of error-checking in my code that will redirect if an ID with no record was entered, but it just doesn't work. The code doesn't affect the page functionality if I entered an ID number with existing records, it only affects it if I entered an ID with no record. Please help. Thanks.


Expand|Select|Wrap|Line Numbers
  1. <?php require_once("includes/db_connect.php"); ?>
  2. <?php require_once("includes/functions.php"); ?>
  3. <?php
  4.  
  5.     $equipid = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipid']))); //equipid number coming from the updatedata.php
  6.  
  7.     $query = "SELECT * FROM tblequipmentmasterlist ";
  8.     $query .= "WHERE equipid =" . $equipid;
  9.     $query .= " LIMIT 1";
  10.  
  11.     $query_result = mysqli_query($db_cxn, $query);
  12.  
  13.  
  14.     if (mysqli_num_rows($query_result) == 0) {
  15.         header ("LOCATION : updatedata.php"); //If record doesn't exist
  16.     } else { //If a record do exist
  17.             while ($row = mysqli_fetch_array ($query_result)) {
  18.                     $equipname = $row['equipname'];
  19.                     $manufacturer = $row['manufacturer'];
  20.                     $serno = $row['serno'];
  21.                     $modelno = $row['modelno'];
  22.                     $capacity = $row['capacity'];
  23.                     $curloc = $row['curlocation'];
  24.                     $equipcode = $row['equipcode'];
  25.                     $seqno = $row['seqno'];
  26.                     $adddate = $row['adddate'];
  27.                  }
  28.             }
  29.  
  30. ?>
  31. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  32. <html xmlns="http://www.w3.org/1999/xhtml">
  33. <head>
  34. <title>EST-Equipment Intranet-Calibration-Update Equipment Record</title>
  35. <meta http-equiv="Content-Language" content="English" />
  36. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  37. <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
  38. <style type="text/css">
  39. <!--
  40. .style1 {
  41.     color: #000000;
  42.     font-size: medium;
  43. }
  44.  
  45. #wrap #content .right .newequipment {
  46.     font-family: Verdana, Arial, Helvetica, sans-serif;
  47.     font-size: 14px;
  48.     font-style: normal;
  49.     font-weight: lighter;
  50.     text-transform: capitalize;
  51.     text-align: left;
  52.     text-indent: 5px;
  53.     margin: 10px;
  54.     padding: 10px;
  55.     width: 350px;
  56. }
  57. -->
  58. </style>
  59.  
  60. <?php include("includes/calheader.php"); ?>
  61.  
  62. <h2>Update Equipment Information Form</h2>
  63. <form action = "processform_update.php" method = "POST">
  64. <div class="DataInput">
  65.   <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname6">
  66.     <tr>
  67.       <td width="200" class="style1">Equipment ID No.</td>
  68.       <td width="507"><input name="equipid" type="text" id="equipid" tabindex="" value="<?php echo $equipid; ?>" size="7" />
  69.      </tr>
  70.   </table>
  71. </div>
  72. <div class="DataInput">
  73.  <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname">
  74.     <tr>
  75.       <td width="200" class="style1">Equipment Name</td>
  76.       <td width="507">
  77.         <input name="equipname" type="text" id="equipname" tabindex="1" value="<?php echo $equipname; ?>" size="40" />
  78.       </td>
  79.     </tr>
  80.   </table>
  81. </div>
  82. <div class="DataInput">
  83.  <table width="708" border="0" cellpadding="0" cellspacing="0" id="Equipname2">
  84.     <tr>
  85.       <td width="200" class="style1">Manufacturer</td>
  86.       <td width="508">
  87.         <input name="manufacturer" type="text" id="manufacturer" tabindex="2" value="<?php echo $manufacturer; ?>" size="40" />
  88.       </td>
  89.     </tr>
  90.   </table>
  91. </div>
  92. <div class="DataInput">
  93.  <table width="561" border="0" cellpadding="0" cellspacing="0" id="Equipname3">
  94.     <tr>
  95.       <td width="200" class="style1">Serial No. (if any)</td>
  96.       <td width="361">
  97.       <input name="serno" type="text" id="serno" tabindex="3" value="<?php echo $serno; ?>" size="30" />
  98.       </td>
  99.     </tr>
  100.   </table>
  101. </div>
  102. <div class="DataInput">
  103.  <table width="561" border="0" cellpadding="0" cellspacing="0" id="Equipname4">
  104.     <tr>
  105.       <td width="200" class="style1">Model No. (if any)</td>
  106.       <td width="361">
  107.       <input name="modelno" type="text" id="modelno" tabindex="4" value="<?php echo $modelno; ?>" size="30" />
  108.       </td>
  109.     </tr>
  110.   </table>
  111. </div>
  112. <div class="DataInput">
  113.   <label class="style6"></label>
  114.   <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname5">
  115.     <tr>
  116.       <td width="200" class="style1">Capacity / Range</td>
  117.       <td width="507">
  118.       <input name="capacity" type="text" id="capacity" tabindex="5" value="<?php echo $capacity; ?>" size="40" />
  119.       </td>
  120.     </tr>
  121.   </table>
  122. </div>
  123. <div class="DataInput">
  124.     <label class="style6"></label>
  125.   <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname6">
  126.     <tr>
  127.       <td width="200" class="style1">Current Location</td>
  128.       <td width="507">
  129.       <input name="curlocation" type="text" id="curlocation" value="<?php echo $curloc; ?>" tabindex="6" size="20" />
  130.       <a href='locationcode.php' target='_blank' class='style7'>...Click here for definition...</a> 
  131.       </td>
  132.     </tr>
  133.   </table>
  134. </div>
  135. <div class="DataInput">
  136.     <label class="style6"></label>
  137.   <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname5">
  138.     <tr>
  139.       <td width="200" class="style1">Equipment Code</td>
  140.       <td width="507">
  141.       <input name="equipcode" type="text" id="equipcode" value="<?php echo $equipcode; ?>" tabindex="7" size="20" />
  142.       <a href='equipmentcode.php' target='_blank' class='style7'>...Click here for definition...</a> 
  143.       </td>
  144.     </tr>
  145.   </table>
  146. </div>
  147. <div class="DataInput">
  148.  <table width="561" border="0" cellpadding="0" cellspacing="0" id="Equipname8">
  149.     <tr>
  150.       <td width="200" class="style1">Sequence Number</td>
  151.       <td width="361">
  152.       <input name="seqno" type="text" id="seqno" tabindex="8" size="7" maxlength="7" value="<?php echo $seqno; ?>" />
  153.       </td>
  154.     </tr>
  155.   </table>
  156. </div>
  157. <div class="DataInput">
  158.  <label class="style6"></label>
  159.   <table width="707" border="0" cellpadding="0" cellspacing="0" id="Equipname5">
  160.     <tr>
  161.       <td width="200" class="style1">Date Added</td>
  162.       <td width="507">
  163.       <input name="adddate" type="text" id="adddate" tabindex="9" value="<?php echo $adddate; ?>" size="20" /> 
  164.       <strong>YYYY-MM-DD</strong> </td>
  165.     </tr>
  166.   </table>
  167. </div>
  168. <p>&nbsp;</p>
  169. <div class="DataInput">
  170. <input type="submit" name="submit" id="submit" value="Submit" />
  171. </div>
  172. </form>
  173. <p><br />
  174. <br />
  175.   <br />
  176.   <br />
  177.   <br />
  178.   </div>
  179.  
  180. <?php require("includes/footer.php"); ?>
  181.  
Also, I would like the EQUIPID text field on this page to be uneditable. I tried DISABLING it, but when I submit the data of this page to be processed, it shows an UNDEFINED INDEX error of my EQUIPID, seems like the EQUIPID variable is not being passed on to the PROCESSING page. I would like the EQUIPID text field to be uneditable so no one can mistakenly edit/update it. Thanks in advance.
Oct 9 '11 #1

✓ answered by Antonio Bacasno

I have finally figured out the problem. It was all syntax. I've put an extra space after LOCATION (header), which PHP doesn't accept. It is now working.

Share this Question
Share on Google+
1 Reply


P: 22
I have finally figured out the problem. It was all syntax. I've put an extra space after LOCATION (header), which PHP doesn't accept. It is now working.
Oct 10 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.