Data Missing at $_POST

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

    Data Missing at $_POST

    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
    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>"; 
    		}
    PROCESS PAGE
    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); 
    	}
    ?>
    MAIN PAGE
    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>
    Attached Files
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    Too much to read,
    just check

    use print_r function to display all the keys and datas, remember index is case sensitive

    Comment

    • Antonio Bacasno
      New Member
      • Sep 2011
      • 22

      #3
      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.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        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.

        Comment

        • Antonio Bacasno
          New Member
          • Sep 2011
          • 22

          #5
          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

          Comment

          Working...