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 -
//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 -
<?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 -
<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>
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
Too much to read,
just check
use print_r function to display all the keys and datas, remember index is case sensitive
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.
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
by: One Handed Man [ OHM ] |
last post by:
Seems like new posts have disapeared from this ng ?
Anyone ??
|
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...
|
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...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |