I am having some problem with posting a data. I want to call the data of EQUIPCODE as a function, but then, during POSTING of the data, it was missing. The odd thing is, EQUIPCODE AND LOCATIONCODE are almost the same scripts, difference only in some variable names. I can POST my LOCATIONCODE but, EQUIPCODE got lost in the middle of POSTING. Instead, it shows this UNDEFINED INDEX error. Could somebody please check my code and guide me to what may be wrong with it. The same EQUIPCODE script in the function will work if I put it as is in my MAIN PAGE, it will not only work if it is called as a function.
FUNCTION
PROCESS PAGE
MAIN PAGE
FUNCTION
Code:
//Equipment Code Function function equipcode() { global $db_cxn; $query_equipcode = "select distinct equipcode from tblequipmentcode order by equipcode"; $query_equipcode_list = mysqli_query($db_cxn, $query_equipcode) or die ("Couldn't find queried items."); echo "<table width='561' border='0' cellpadding='0' cellspacing='0' id='Equipname7'><tr> <td width='200' class='style1'>Equipment Code</td><td width='361'>"; //Create form for EquipCode selection echo "<form action = 'processform.php' method = 'POST'><select name='equipcode' id='equipcode' tabindex='7' >"; while ($row = mysqli_fetch_assoc ($query_equipcode_list)) { extract ($row); echo "<option value = '$equipcode'>$equipcode"; } echo "</select><a href='equipmentcode.php' target='_blank' class='style7'>...Click here for definition...</a></form>"; echo "</td></tr></table>"; } //Location Code Function function locationcode() { global $db_cxn; $query_location = "select distinct locationcode from tbllocation order by locationcode"; $query_location_list = mysqli_query($db_cxn, $query_location) or die ("Couldn't find queried items."); echo "<table width='561' border='0' cellpadding='0' cellspacing='0' id='Equipname6'> <tr><td width='200' class='style1'>Current Location</td><td width='361'>"; //Create form for LocationCode selection echo "<form action = 'processform.php' method = 'POST'><select name='curlocation' id='curlocation' tabindex='6' >"; while ($row = mysqli_fetch_assoc ($query_location_list)) { extract ($row); echo "<option value = '$LocationCode'>$LocationCode"; } echo "</select><a href='locationcode.php' target='_blank' class='style7'>...Click here for definition...</a></form>"; echo "</td></tr></table>"; }
Code:
<?php include("includes/db_connect.php"); ?> <?php require_once("includes/functions.php"); ?> <?php $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['dateYr']))). "-"; $addDate .= mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['dateMO']))). "-"; $addDate .= mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['dateDay']))); $query_add = "INSERT INTO tblequipmentmasterlist (equipname, manufacturer, serno, modelno, capacity, curlocation, equipcode, seqno, adddate) VALUES ('{$equipname}','{$manufacturer}','{$serno}','{$modelno}', '{$capacity}','{$curloc}','{$equipcode}','{$seqno}','{$addDate}')"; if ($query_add != null) { mysqli_query($db_cxn, $query_add); echo "<pre>"; echo "<h4>You have successfully added the following records to the database : </h4>"; echo "<hr>"; echo "<br />"; echo "Equipment Name : <b>{$equipname}</b><br />"; echo "Manufacturer : <b>{$manufacturer}</b><br />"; echo "Serial No. : <b>{$serno}</b><br />"; echo "Model No. : <b>{$modelno}</b><br />"; echo "Capacity/Range : <b>{$capacity}</b><br />"; echo "Current Location : <b>{$curloc}</b><br />"; echo "Equipment Code : <b>{$equipcode}</b><br />"; echo "Sequence No. : <b>{$seqno}</b><br />"; echo "Date Added : <b>{$addDate}</b>"; //echo print_r($_POST); //echo var_dump($_POST); echo "</pre>"; echo "<hr>"; echo "<form action='newequipment.php' method='POST'>"; echo "<input type='submit' name='submit' id='submit' value='Continue' /></form>"; //header ("Location: processform_old.php"); //exit; } else { echo "<p>Record was not added : ". $query_add. " Please contact the site administrator.</p>"; echo "<p>" . mysqli_error($db_cxn) . "</p>"; } ?> <?php if (isset($db_cxn)) { mysqli_close($db_cxn); } ?>
Code:
<div class="DataInput"> <?php //Location Code Function locationcode(); /*$query_location = "select distinct LocationCode from tbllocation order by LocationCode"; $query_location_list = mysqli_query($db_cxn, $query_location) or die ("Couldn't find queried items."); echo "<table width='561' border='0' cellpadding='0' cellspacing='0' id='Equipname6'> <tr><td width='200' class='style1'>Current Location</td><td width='361'>"; echo "<select name='curlocation' id='curlocation' tabindex='6' >"; while ($row = mysqli_fetch_assoc ($query_location_list)) { extract ($row); echo "<option value = '$LocationCode'>$LocationCode"; } echo "</select><a href='locationcode.php' target='_blank' class='style7'>...Click here for definition...</a></form>"; echo "</td></tr></table>"; */ ?> </div> <div class="DataInput"> <?php //Equipment Code Function equipcode(); /*$query_equipcode = "select distinct EquipCode from tblequipmentcode order by EquipCode"; $query_equipcode_list = mysqli_query($db_cxn, $query_equipcode) or die ("Couldn't find queried items."); echo "<table width='561' border='0' cellpadding='0' cellspacing='0' id='Equipname7'><tr> <td width='200' class='style1'>Equipment Code</td><td width='361'>"; echo "<select name='equipcode' id='equipcode' tabindex='7' >"; while ($row = mysqli_fetch_assoc ($query_equipcode_list)) { extract ($row); echo "<option value = '$EquipCode'>$EquipCode"; } echo "</select><a href='equipmentcode.php' target='_blank' class='style7'>...Click here for definition...</a></form>"; echo "</td></tr></table>";*/ ?> </div>
Comment