I am having a problem keeping hold of information over several pages...
page 1 - has a query that lists all the stock items carried by a certain department.
using this information I have created a user input form to allow the entry of quantites for each item
page 2 - processes the form and adds the information to the database
everything is working fine apart from one variable 'StockCode' ........ I cannot get it to maintain the correct information across the pages and then into the database.
Say for example I expecting;
Stock Code / Item / Previous Month / This Month
200 / sugar / 24 / 22
199 / flour / 16 / 18
The user has input the values 22 for sugar and 18 for flour, all the rest of the information has come from a query. I get the correct information on this page, but I want to carry all of this over to the process page and then add the stock code and this months figures into the database. When I echo out the Stock Code on the process page, instead of 200 / 199 I get 1 / 9 ( I have no idea where these figures have come from) and that is what gets entered in to the database (1 and 9).
I need to find out what is going wrong in the change from page to page - the query echos out the correct values in the form, but when they go to the process page they change completely............
I have further tested this by echoing our what I would expect to be the arrays
in the process page I tried
print_r ($POST['data']);
print_r ($POST['StockCode']);
I got the expected array for the $data variable but didn't get an array at all for the for the Stock Code (just 1's and 9's)
Array ( [0] => 22 [1] => 18 ) 19919
Code for User Input Form
require_once ('../mysql_connect.php'); //connect to the database
//query goes here to get this variable
$CRef = $row101["CRef"];
//query goes here to get this variable
$ConRef = $row11["ConRef"];
//query goes here to get this variable
$SRef = $row["SId"];
//list stock items
$query = "SELECT (SNo) AS SNo, (CName) AS Location, (MId) AS MId FROM `tblM` WHERE SRef = '$SRef' AND ConRef = '$ConRef' ";
$result2 = mysql_query($query)
or die(mysql_error());
if ($result2)
{
echo' <form action="process.php" method="POST" > <FONT FACE="arial" SIZE="1">
<table align="centre" cellspacing="0" cellpadding="0">
<tr valign="top">
<td align="right" width="50"></td>
<td align="right" width="30"><b>Item</b></td>
<td align="right" width="170"><br>Previous Month </td>
<td align="left" width="200"><b><br> This Month</b></td>
</tr >';
while ($row2 = mysql_fetch_array($result2,MYSQL_NUM))
{
$query= "SELECT (MRef) AS MRef, Max(data) As LastResult
FROM tblResults
WHERE MRef = '".$row2[2]."'
AND CRef = $CRef
AND SRef = $SRef
AND ConRef = $ConRef
GROUP BY MRef, CRef, SRef, ConRef";
$result3 = mysql_query($query) or die (mysql_error());
$row3 = mysql_fetch_array($result3);
echo "
<td width=\"50\" align=\"left\"> <input type=\"hidden\" name=\"StockCode[]\" value=\"{$row2[0]}\"></td>
<td width=\"30\" align=\"left\"> $row3[2]></td>
<td width=\"170\" align=\"right\"> $row3[1]   </td>
<td width=\"200\" align=\"left\"> <input type=\"text\" name=\"data[]\"></td>
";
}
echo "</font></tr>\n";
} // close while loop
} //close main if
echo '</font></table>';
echo "<br><p align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Submit\"> ";
echo '</form>';
Code For processing the form
require_once ('../mysql_connect.php'); //connect to the database
//note: $UserId is set in previous part of code on this page
$data = strip_tags(trim($_POST['data'][$i]));
$MId = ($_POST['StockCode'][$i]);
$query = "REPLACE INTO tblResults (MRef,Qty,LoadedBy) VALUES ('$MId','$data','$UserId')";
$result = mysql_query($query)
or die(mysql_error());