I have a form that displays a table with a checkbox along with name, description, vendor, date, cost and comments. I can display the table from the database, but if I select 2 checkboxes maybe from 10 records, I get the results from 2 selections but always the last record. This is what I have:
echo "<form method='post' action='purchview.php?'>";
echo "<table border='1'>";
echo "<tr> <th>Selection</th> <th>Name</th> <th>Description</th> <th>Vendor</th> <th>Date</th>
<th>Cost</th> <th>Comments</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($table))
{
// Print out the contents of each row into a table
echo "<tr>";
echo "<td><input type='checkbox' name='chkbox[]'
value='on'
<? if($chkbox==='on') {echo 'checked';}?></td>";
echo "<td><input type='Text' name='user_name' value={$row['user_name']}></td>";
echo "<td><input type='Text' name='Description' value={$row['Description']}></td>";
echo "<td><input type='Text' name='Vendor' value={$row['Vendor']}></td>";
echo "<td><input type='Text' name='Date' value={$row['Date']}></td>";
echo "<td><input type='Text' name='Cost' value={$row['Cost']}></td>";
echo "<td><input type='Text' name='Comments' value={$row['Comments']}></td>";
echo "</tr>";
}
echo "<td>$row<align='center'><input type='submit' name='submit' value='submit'></td>";
echo "</table>";
echo "</form>";
This is what I have for purchview.php:
<?php
foreach ($POST['chkbox'] as $value)
{
echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Description</th> <th>Vendor</th> <th>Date</th>
<th>Cost</th> <th>Comments</th> </tr>";
// Print out the contents of each row into a table
echo "<tr><td>";
echo "$POST[user_name]";
echo "</td><td>";
echo "$POST[Description]";
echo "</td><td>";
echo "$POST[Vendor]";
echo "</td><td>";
echo "$POST[Date]";
echo "</td><td>";
echo "$POST[Cost]";
echo "</td><td>";
echo "$_POST[Comments]";
echo "</td>";
echo "</tr>";
echo "</table>";
}
?>
Please help!!!! Thanks, tcooper02