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

No Record Found Error Handling

P: 22
Please help me. I would like to put some code that will produce an error message if the ID number entered is still non-existent, then returns to the previous page. I've tried using mysqli_num_rows, but it doesn't work, maybe I used the wrong function. Please find the attached code.

***RETRIEVE DATA OF CORRESPONDING ID NUMBER***
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.  
Another thing, I would like the EQUIPID text field on this page to be un-editable. I tried disabling the EQUIPID text field, but it gives an Undefined Index error of EQUIPID, the EQUIPID variable was missing. Please advise. Thanks.
Oct 4 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

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