hello
I have a list of records in an html form which I would like to add line by line into a results table in the database.....
On the following code, I can only get the last record to add to the database.
I am thinking I need some form of a loop to add all of the records, but so far haven't been able to come up with anything.
Any ideas? - thanks
CODE FOR FORM
session_start ();
require_once ('../connect.php'); //connect to the database
$query = "SELECT `SectionRef` FROM `tblUser` WHERE `CLogIn` = '$username'";
$result = mysql_query($query)
or die(mysql_error());
$row = mysql_fetch_array($result);
$SectionRef = $row["SectionRef"];
$query = "SELECT `List` FROM `tblMachine` WHERE `SectionRef` = '$SectionRef'";
$result1 = mysql_query($query)
or die ("no such info");
$row1 = mysql_fetch_array($result1);
$List = $row1["List"];
$query = "SELECT (Model) AS Model, (SerialNo) AS SerialNo, (CommonName) AS Location FROM `tblMachine` WHERE SectionRef = '$SectionRef' ";
$result2 = mysql_query($query)
or die(mysql_error());
if ($result2)
{
echo '<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>
</tr>';
while ($row2 = mysql_fetch_array($result2,MYSQL_NUM))
{
echo "<form action=\"process.php\" method=\"post\">
<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=\"200\" align=\"left\"> $row2[3] <input type=\"text\" name=\"Size\"> </td>
<td width=\"300\" align=\"left\"> $row2[4] <input type=\"text\" name=\"Colour\"></td><br>
</font></tr>\n";
} // close while loop
} // close if
echo '</table></font>';
echo "<br><p align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Submit\">
</form>";
?>
CODE FOR PROCESSING FORM RESULTS
session_start ();
require_once ('../connect.php'); //connect to the database
$Size = $_POST[Size];
$Colour = $_POST[Colour];
$query = "SELECT `SectionRef` FROM `tblUser` WHERE `CLogIn` = '$username'";
$result = mysql_query($query)
or die(mysql_error());
$row = mysql_fetch_array($result);
$SectionRef = $row["SectionRef"];
$query = "SELECT `MachineId` FROM `tblMachine` WHERE `SectionRef` = '$SectionRef'";
$result1 = mysql_query($query)
or die(mysql_error());
$row1 = mysql_fetch_array($result1);
$MachineId = $row1["MachineId"];
$Size = trim($Size);
$Size = strip_tags($Size);
$Colour = trim($Colour);
$Colour = strip_tags($Colour);
$query = "INSERT INTO tblResults (MachineRef,Size,Colour,LoadedBy,LoadedWhen)
VALUES ('$MachineID','$Size','$Colour','$Username',NOW())";
$result2 = mysql_query($query)
or die(mysql_error());
echo "<p></p><p></p><p></p>
<p><div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"3\"><b><font color=\"#FF0000\">Thank you $username, <br> <br> your details have been added.</font></b></font></div></p>"