I have outputted several rows from a MySQL table together with a checkbox on each row. I would like to select rows via the checkboxes and submit the selected rows to another table but when I click the submit button only the value of the last row is inserted. I know I have to introduce a counter but I am not sure how to implement this. Could someone kindly show me how to? See code snippet below:
$sql="SELECT * FROM student WHERE semester='$sem'";
$result=mysql_query($sql)or die(mysql_error());
echo "<table align=\"center\" width=\"40%\" border=\"1\">";
echo "<tr><th colspan=\"3\">SEMESTER ".$sem." STUDENTS</th></tr>";
echo "<tr>";
echo "<th>Add</th>";
echo "<th>StudentID</th>";
echo "<th>Student Name</th>";
echo "</tr>";
while ($row = mysql_fetch_array($result)){
$id=$row['id'];
$sid=$row['studentid'];
$fname=$row['firstname'];
$lname=$row['lastname'];
echo "<tr>";
echo "<td align=\"center\"><input type=\"checkbox\" name=\"add\" /></td>";
echo "<td align=\"center\"><input type=\"text\" name=\"stdid\" value=\"".$sid."\" READONLY /></td>";
echo "<td align=\"center\"><input type=\"text\" name=\"stdname\" value=\"".$fname." ".$lname."\" READONLY /></td>";
echo "</tr>";
}
echo "</table>";