Hello
What I am trying to do (most unsucessfully) is take the information from a form put the results in a database.
I can show you what I have already, and tell you that the code doesn't work as it should.......!
session_start ();
$_SESSION['user_id'] = $row[0];
$_SESSION['username'] = $row[1];
require_once ('../connect.php'); //connect to the database
include ('header.php'); //show header
$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 (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>
</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]} <input type=\"text\" name=\"Size[]\"> </td>
<td width=\"300\" align=\"left\"> {$row2[5]} <input type=\"text\" name=\"Colour[]\"></td><br>
</font></tr>\n";
} // close while loop
} // close if
echo '</table>';
echo "<br><p align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Submit\"> ";
echo '</form>';
This form 'works' in as much as it shows the information it should.
From this form I am trying to take the information MachineId, Size, Colour to put in the database.
I am also going to add the username information which (hopefully) will come from the session variable.
Another problem I have here is there will be more than one record/row in this form, so I need to collect the 4 bits of information for each row and put them row by row into the database using the MachineId as the key.
I thought I had is sussed by using the next code as the page process.php, but it doesn't work, and when I tested it by echoing out $result, it just came up with 1 as the output (??).
session_start ();
require_once ('../connect.php'); //connect to the database
include ('header.php'); //show header
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 = strip_tags(trim($_POST[MachineId][$i]));
$query = "INSERT INTO tblResults (MachineRef,Size,Colour,LoadedBy,LoadedWhen)
VALUES ('$MachineId','$Size','$Colour','$username',NOW())
";
$result = 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 information has been added<br> and will be processed accordingly.</font></b></font></div></p>"
This code is inputting the Size information into the database and the LoadedWhen through the NOW() function, but nothing else.
Although $username is sucessfully being used in the 'thank you' echo, it isn't being put in the database.........
The database is creating a record for each row the table created, which is good, I just need to get the results in as well(!)
Do you think the problem could be in the way the form is written, so it isn't carrying over the information to the process.php page?
OR is it more a question that the sql part of the code on page process.php isn't correctly written so the information won't go into the database?
Some of you might recognise this problem...... I have been posting on the forum for the past 10 days or so trying to get to the bottom of this....... Sorry to be a pain in the neck but I really need some help with this. I've got to have this code working by the end of this week for a website I am working on, so I am prepared to take any suggestions and try them out.......thanks in advance.