I have worked on all of your suggestions but I still cannot get the results into the table.
I must admit I wasted a lot of time last night and this morning re-writting everything from scratch because I changed something and the next thing that happened was I could even get the results of the first query into the table on the first page....... it turns out (I think ?!) that the session kept timing out whilst I was fiddling with the code and now if I log out completely and go back in it works OK (us newbies are hopeless I know!)
ANYHOW.........
this is what I have got so far
code for creating query on database and showing results in table format for user to add information.....
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 '<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=\"20\" align=\"left\"> {$row2[3]} <input type=\"hidden\" name=\"s\" 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>
</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 page process.php to put the results of the form into a results table in the database.......
session_start ();
require_once ('../connect.php'); //connect to the database
include ('header.php'); //show header
echo "machineid = '$MachineId' <br>
Size= '$Size' <br>
Colour = '$Colour' <br>
Username = '$username' ";
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]));
$username = strip_tags(trim($_SESSION[username][$i]));
$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>"
I have added the echo on the 4 fields of information I want to add to the database (Size,Colour,MachineId,Username) to test if they work. The output I am getting is - Size = 'Array' Colour = '' MachineID = '' username = 'John.Lennon' .
- From this I know that the username variable works, but it still isn't going into the database.
- The Size information is being added
- Colour and MachineId are not being added
However on $username, I am also trying to put this variable in the echo thank you message, but it does not work.
So I know I am asking a lot here, but things I am stuck on are;
- how to get all 4 fields / variables into the table for each record created in the very first query?
- why won't the username variable work on the last echo thankyou message?
- on the table in the first code, why isn't the hidden field hidden (i can see the information in the table) ?
If anyone can have a look at this and see where I am going wrong I would be very grateful. (mtimdog has been a great help so far, but I feel as if I am taking up far too much of his time 😉 )
thanks in advance to anyone who has a look......