473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

No Record Found Error Handling

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
0 1628

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

Similar topics

1
by: monika | last post by:
hi ... I want to do error handling in my application. I have made a complete application. but when I encounter errors (like mentioned below) I want to do error handling. how can I do it? I...
1
by: monika | last post by:
hi... when I try to insert a duplicate record I get the primary key error. which is good. but I want to generate a user friendly error ... telling the user that u have got this error because u r...
2
by: aaj | last post by:
Hi all I have an automated application, that runs in the middle of the night. If certain 'non system' errors occur (things like malformed files, missing files etc..), I send an automatic Email...
3
by: WindAndWaves | last post by:
I am writing error handling procedures at the moment. Here are some questions: 1. Can you write a procedure that picks up any error and deals with it no matter where it happens in the database?...
10
by: David | last post by:
Hello I am trying to collect errors and record them in a table instead of a popup message stopping my code. It seems to work ok, but when I try to add ERR.Description to my code it fails on Syntax...
4
by: aaj | last post by:
Hi all I have an automated application, that runs in the middle of the night. If certain 'non system' errors occur (things like malformed files, missing files etc..), I send an automatic Email...
4
by: James Radke | last post by:
Hello, I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module...
33
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on...
7
by: Garth Wells | last post by:
I'm trying to create a DAL and am wondering what's the proper way to handle errors in this Insert method. public string Insert() { Database db = DatabaseFactory.CreateDatabase(); string...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.