I have a problem whereby an array I am creating as part of a form isn't being carried over to a results page where I am trying to insert the results into a database......
code for the form;
$query = "SELECT (Model) AS Model, (SerialNo) AS SerialNo, (CommonName) AS Location, (MachineId) AS MachineId FROM `tblMachine` WHERE SectionRef = '$SectionRef' ";
$result2 = mysql_query($query)
or die(mysql_error());
if ($result2)
{
echo' <form action="process.php" method="POST">
<table align="centre" cellspacing="0" cellpadding="0">
<tr>
<td align="left"><b>Model</b></td>
<td align="left"><b>Serial Number</b></td>
<td align="left"><b>Location</b></td>
<td align="left"></td>
<td align="left"></td>
<td align="left"><b>Information</b></td>
<td align="left"></td>
</tr>';
while ($row2 = mysql_fetch_array($result2,MYSQL_NUM))
{
echo "<tr><font face=\"Arial, Helvetica, sans-serif\">
<td width=\"70\" align=\"left\"> {$row2[0]}</td>
<td width=\"120\" align=\"left\"> {$row2[1]}</td>
<td width=\"200\" align=\"left\"> {$row2[2]}</td>
<td width=\"20\" align=\"left\"> <input type=\"hidden\" name=\"MachineId[]\" value\"{$row2[3]}\" </td>
<td width=\"200\" align=\"left\"> {$row2[4]}Size <input type=\"text\" name=\"Size[]\"> </td>
<td width=\"300\" align=\"left\"> {$row2[5]} Colour <input type=\"text\" name=\"Colour[]\"></td><br> ";
}
echo "</font></tr>\n";
} // close while loop
} //close if
echo '</table>';
echo "<br><p align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Submit\"> ";
echo '</form>';
the form draws information from tblMachine, presents it to the user who adds size / colour information, submits the form and then the results are Inserted into the database tblResults - simple !
code to process results;
if (isset($_POST['Size']))
{
$arr_size = count($_POST['Size']);
for ($i=0;$i< $arr_size;$i++)
{
$Size = strip_tags(trim($_POST['Size'][$i]));
$Colour = strip_tags(trim($_POST['Colour'][$i]));
$MachineId = ($_POST['MachineId'][$i]);
$query = "INSERT INTO tblResults (DateLogRef,MachineRef,Size,Colour,LoadedBy)
VALUES('$DateLogRef','$MachineId','$Size','$Colour','$UserId')";
$result = mysql_query($query)
or die(mysql_error());
}
}
$DateLogRef and $UserId are variables that have been set previously in the code and they work OK.
Because there will be more than one row of results from the form I have set it up so that it creates an array for each of the variables.
This is happening OK, where there are 4 rows in the form, 4 rows are created in the database when the results are inserted.
Colour / Size / LoadedBy / DateLogRef information all go into the database OK but for days and days I have been trying to get the MachineId results into the database and it just isn't happening.
I have tested it by using
print_r($_POST['MachineId']);
print_r($_POST['Colour']);
print_r($_POST['Size']);
and it outputs ;
Array ( [0] => [1] => [2] => [3] => )
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )
Array ( [0] => s [1] => m [2] => l [3] => l )
the results of the array for colour and size come out, but nothing for machineid.......... WHY ?!
can anyone see what I am doing wrong?
thanks in advance