473,412 Members | 2,075 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,412 software developers and data experts.

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
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, 182 views)
File Type: jpg MainPage.jpg (31.3 KB, 166 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.

4 2640
johny10151981
1,059 1GB
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
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
8,658 Expert Mod 8TB
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
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

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

Similar topics

7
by: Jim Mitchell | last post by:
Am I correct to assume that any changes to a control's properties or changes to a ViewState("Name") are not available until after the Page_Load fires? If so, how can you set a flag in a control...
0
by: warlord | last post by:
In order to save typing, I've borrowed the text from a post of nearly 12 months ago.....but the problem still exists. I've been banging my head all day with this, so I'm hoping someone has some...
15
by: Dominic Tocci | last post by:
When I submit a form to an asp page, the request.form is not getting the data. This only happens on my local copy of IIS, and not on my web host. It's a simple request.form, so I know it's not a...
2
by: Shannon Rotz | last post by:
I have a function in a Microsoft Access module (below) which creates a Word XP Mailmerge document, drawing the data from Access XP. I can get the connection to work fine. However, when I create...
1
by: Paul | last post by:
Hi trying to deploy to a web server and got the system.data missing. I found the dll on the local machine and copied it over to the bin directory on the server. It found it but then got the...
5
by: One Handed Man [ OHM ] | last post by:
Seems like new posts have disapeared from this ng ? Anyone ??
6
by: Boldgeek | last post by:
I am trying to develop an app that will allow automatic updating of a web form which uses multipart/form-data enctype (as it MIGHT be sending an image) I have an example form, which when...
1
by: Scott Cupstid | last post by:
We are working on a VB.NET application using SQLClient command objects to post data to the underlying SQL Server 2000 database. The application is deployed in a multi-user environment with no more...
0
by: joehaxor | last post by:
Hi! Thanks if anyone can answer this probably easy question. ASP.NET C# I have a .aspx page with a form that used POST method to send information (action="searchresults.aspx") However...
1
by: Gareth Jones | last post by:
Hi all, I am attmepting to run a query based on 2 tables. In the query there are 3 fields from table 1 and 2 fields from table 2. The common field in both is Change.ID The query is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.