No Record Found Error Handling

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Antonio Bacasno
    New Member
    • Sep 2011
    • 22

    #1

    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***
    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 number coming from the updatedata.php
    	
    	$query = "SELECT * FROM tblequipmentmasterlist ";
    	$query .= "WHERE equipid =" . $equipid;
    	$query .= " LIMIT 1";
    	
    	$query_result = mysqli_query($db_cxn, $query);
    	
    	
    	if (mysqli_num_rows($query_result) == 0) {
    		header ("LOCATION : updatedata.php"); //If record doesn't exist
    	} else { //If a record do exist
    			while ($row = mysqli_fetch_array ($query_result)) {
    					$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>&nbsp;</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"); ?>
    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.
Working...