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

Data Missing at $_POST

P: 22
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
Expand|Select|Wrap|Line Numbers
  1. //Equipment Code Function
  2.     function equipcode() {
  3.         global $db_cxn;
  4.         $query_equipcode = "select distinct equipcode from tblequipmentcode order by equipcode";
  5.         $query_equipcode_list = mysqli_query($db_cxn, $query_equipcode)
  6.             or die ("Couldn't find queried items.");
  7.  
  8.      echo "<table width='561' border='0' cellpadding='0' cellspacing='0' id='Equipname7'><tr>
  9.           <td width='200' class='style1'>Equipment Code</td><td width='361'>";
  10.  
  11.         //Create form for EquipCode selection     
  12.       echo "<form action = 'processform.php' method = 'POST'><select name='equipcode' id='equipcode' tabindex='7' >";
  13.       while ($row = mysqli_fetch_assoc
  14.           ($query_equipcode_list))
  15.         {
  16.             extract ($row);
  17.             echo "<option value = '$equipcode'>$equipcode";
  18.         }        
  19.       echo "</select><a href='equipmentcode.php' target='_blank' class='style7'>...Click here for definition...</a></form>";
  20.       echo "</td></tr></table>";
  21.     }
  22.  
  23.  
  24.     //Location Code Function
  25.     function locationcode() {
  26.         global $db_cxn;
  27.         $query_location = "select distinct locationcode from tbllocation order by locationcode";
  28.         $query_location_list = mysqli_query($db_cxn, $query_location)
  29.             or die ("Couldn't find queried items.");
  30.  
  31.          echo "<table width='561' border='0' cellpadding='0' cellspacing='0' id='Equipname6'>
  32.             <tr><td width='200' class='style1'>Current Location</td><td width='361'>";
  33.  
  34.            //Create form for LocationCode selection
  35.         echo "<form action = 'processform.php' method = 'POST'><select name='curlocation' id='curlocation' tabindex='6' >";
  36.            while ($row = mysqli_fetch_assoc
  37.            ($query_location_list))
  38.         {
  39.             extract ($row);
  40.             echo "<option value = '$LocationCode'>$LocationCode";
  41.         }
  42.  
  43.           echo "</select><a href='locationcode.php' target='_blank' class='style7'>...Click here for definition...</a></form>";
  44.  
  45.           echo "</td></tr></table>"; 
  46.         }
PROCESS PAGE
Expand|Select|Wrap|Line Numbers
  1. <?php include("includes/db_connect.php"); ?>
  2. <?php require_once("includes/functions.php"); ?>
  3.  
  4. <?php
  5.  
  6.     $equipname = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['equipname'])));
  7.     $manufacturer = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['manufacturer'])));
  8.     $serno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['serno'])));
  9.     $modelno = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['modelno'])));
  10.     $capacity = mysqli_real_escape_string($db_cxn, trim(htmlspecialchars($_POST['capacity'])));
  11.     $curloc = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['curlocation'])));
  12.     $equipcode = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['equipcode'])));
  13.     $seqno = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['seqno'])));    
  14.     $addDate = mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['dateYr']))). "-";
  15.     $addDate .= mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['dateMO']))). "-";
  16.     $addDate .= mysqli_real_escape_string($db_cxn, trim(strip_tags($_POST['dateDay'])));
  17.  
  18.     $query_add = "INSERT INTO tblequipmentmasterlist (equipname, manufacturer, serno,
  19.                     modelno, capacity, curlocation, equipcode, seqno, adddate) 
  20.                     VALUES ('{$equipname}','{$manufacturer}','{$serno}','{$modelno}',
  21.                     '{$capacity}','{$curloc}','{$equipcode}','{$seqno}','{$addDate}')";
  22.  
  23.     if ($query_add != null) {
  24.         mysqli_query($db_cxn, $query_add);
  25.         echo "<pre>";
  26.         echo "<h4>You have successfully added the following records to the database : </h4>";
  27.         echo "<hr>";
  28.         echo "<br />";
  29.         echo "Equipment Name : <b>{$equipname}</b><br />";
  30.         echo "Manufacturer : <b>{$manufacturer}</b><br />";
  31.         echo "Serial No. : <b>{$serno}</b><br />";
  32.         echo "Model No. : <b>{$modelno}</b><br />";
  33.         echo "Capacity/Range : <b>{$capacity}</b><br />";
  34.         echo "Current Location : <b>{$curloc}</b><br />";
  35.         echo "Equipment Code : <b>{$equipcode}</b><br />";
  36.         echo "Sequence No. : <b>{$seqno}</b><br />";
  37.         echo "Date Added : <b>{$addDate}</b>";
  38.         //echo print_r($_POST);
  39.         //echo var_dump($_POST);
  40.         echo "</pre>";
  41.         echo "<hr>";
  42.         echo "<form action='newequipment.php' method='POST'>";
  43.         echo "<input type='submit' name='submit' id='submit' value='Continue' /></form>";
  44.         //header ("Location: processform_old.php");
  45.         //exit;
  46.         } else {
  47.             echo "<p>Record was not added : ". $query_add.  " Please contact the site administrator.</p>";
  48.             echo "<p>" . mysqli_error($db_cxn) . "</p>";
  49.         }                
  50. ?>
  51.  
  52. <?php 
  53.     if (isset($db_cxn)) {
  54.         mysqli_close($db_cxn); 
  55.     }
  56. ?>
MAIN PAGE
Expand|Select|Wrap|Line Numbers
  1. <div class="DataInput">
  2.     <?php
  3.     //Location Code Function
  4.     locationcode(); 
  5.         /*$query_location = "select distinct LocationCode from tbllocation order by LocationCode";
  6.         $query_location_list = mysqli_query($db_cxn, $query_location)
  7.             or die ("Couldn't find queried items.");
  8.  
  9.          echo "<table width='561' border='0' cellpadding='0' cellspacing='0' id='Equipname6'>
  10.             <tr><td width='200' class='style1'>Current Location</td><td width='361'>";
  11.  
  12.            echo "<select name='curlocation' id='curlocation' tabindex='6' >";
  13.            while ($row = mysqli_fetch_assoc
  14.            ($query_location_list))
  15.         {
  16.             extract ($row);
  17.             echo "<option value = '$LocationCode'>$LocationCode";
  18.         }
  19.  
  20.           echo "</select><a href='locationcode.php' target='_blank' class='style7'>...Click here for definition...</a></form>";
  21.  
  22.           echo "</td></tr></table>"; */
  23.     ?>
  24. </div>
  25. <div class="DataInput">
  26.     <?php
  27.         //Equipment Code Function
  28.         equipcode();
  29.             /*$query_equipcode = "select distinct EquipCode from tblequipmentcode order by EquipCode";
  30.             $query_equipcode_list = mysqli_query($db_cxn, $query_equipcode)
  31.                 or die ("Couldn't find queried items.");
  32.  
  33.          echo "<table width='561' border='0' cellpadding='0' cellspacing='0' id='Equipname7'><tr>
  34.               <td width='200' class='style1'>Equipment Code</td><td width='361'>";
  35.  
  36.  
  37.           echo "<select name='equipcode' id='equipcode' tabindex='7' >";
  38.           while ($row = mysqli_fetch_assoc
  39.               ($query_equipcode_list))
  40.             {
  41.                 extract ($row);
  42.                 echo "<option value = '$EquipCode'>$EquipCode";
  43.             }        
  44.           echo "</select><a href='equipmentcode.php' target='_blank' class='style7'>...Click here for definition...</a></form>";
  45.           echo "</td></tr></table>";*/
  46.     ?>
  47. </div>
Attached Images
File Type: jpg UndefinedIndexEquipCode.jpg (83.8 KB, 136 views)
File Type: jpg MainPage.jpg (31.3 KB, 127 views)
Sep 26 '11 #1

✓ answered by Dormilich

the problem lies within your HTML. you have created separate forms for the equipcode and the current location and since you cannot submit two forms at the same time, one of them (in this case equipcode) is missing in the final submission.

if I were to recommend a solution, Iíd recommend a totally different approach in creating the HTML output. you create the complete (and HTML error free) form separately as a HTML template, load it and fill it with the values from your DB (also called conten-code-separation).

PS. nested forms ainít allowed either.

Share this Question
Share on Google+
4 Replies


100+
P: 1,059
Too much to read,
just check

use print_r function to display all the keys and datas, remember index is case sensitive
Sep 27 '11 #2

P: 22
The EQUIPCODE function is basically the same scripts that would work if I just put it as any other scripts on my MAIN PAGE. I want to put the EQUIPCODE scripts in a function so that I can reuse it. If EQUIPCODE works if it isn't called from a function, I think it would also work if I put the scripts inside a function and call it from there. What's confusing is that LOCATIONCODE function works fine when LOCATIONCODE and EQUIPCODE are practically the same scripts. I've tried PRINT_R and VAR_DUMP and every other data was present except for the EQUIPCODE data.
Sep 27 '11 #3

Dormilich
Expert Mod 5K+
P: 8,639
the problem lies within your HTML. you have created separate forms for the equipcode and the current location and since you cannot submit two forms at the same time, one of them (in this case equipcode) is missing in the final submission.

if I were to recommend a solution, Iíd recommend a totally different approach in creating the HTML output. you create the complete (and HTML error free) form separately as a HTML template, load it and fill it with the values from your DB (also called conten-code-separation).

PS. nested forms ainít allowed either.
Sep 27 '11 #4

P: 22
Whew! I've resolved my issues, many thanks to this forum. I copied the EQUIPCODE, LOCATIONCODE and DATESELECTION scripts from my MAIN page and replace those inside the FUNCTIONS, and it worked! The form tags in my FUNCTION may have been the culprit. Thanks for the reminder, I didn't notice that I've already nested forms. Newbie errors. XD
Sep 28 '11 #5

Post your reply

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