I'm trying to delete a whole row that contains questiontext and type. The functionality is working as desired in case of deleting. However it's always deleting the final row added and not the ones checked. Any suggestions why?
case 'Addquiz':
$sql = "SELECT id,questiontext,type FROM questioninfo ORDER BY type DESC ";
$result = mysqli_query($con,$sql);
$selectedtable = "<form method='post' action=''>\n";
$selectedtable .= "<table class='sortable'>\n<tr><th>Select</th><th>Question</th><th>Type</th></tr>\n";
while($row = mysqli_fetch_assoc($result)) {
$rowID = $row['id'];
$text = $row['questiontext'];
$type = $row['type'];
$selectedtable .= "<tr><td><input type='checkbox' name='delete' value='Delete' style='margin:20px;'></td><td><input type='text' name='QuestionText[$rowID]' value='$text' style=' width:600px; text-align:left;'></td><td><select name='Type[$rowID]' style='margin:10px; height:35px'><option selected='selected'></option><option value='$type'>Performace</option><option value='$type'>Loyalty</option></select></td></tr>\n";
}
$selectedtable .= "</table>\n";
$selectedtable .= "<input type='submit' name='addquestion' value='Add Question' style='width:140px; height:30px; text-align:center; padding:0px;'>\n";
$selectedtable .= "<input type='submit' name='submit' value='Update' style='width:80px; height:30px; text-align:center; padding:0px;'>\n";
$selectedtable .= "<input type='submit' name='del' value='Delete' style='width:80px; height:30px; text-align:center; padding:0px;'>\n";
$selectedtable .= "</form>\n";
if(isset($_POST['submit']))
{
foreach($_POST['QuestionText'] as $rowID => $text)
{
$sql = "UPDATE questioninfo SET questiontext = '$text', type = '$type' WHERE id = '$rowID'";
mysqli_query($con,$sql);
}
}
if(isset($_POST['addquestion']))
{
$sql="INSERT INTO `questioninfo` (`ID`) VALUES (NULL)";
mysqli_query($con,$sql);
}
if(isset($_POST['del']))
{
$sql="DELETE FROM questioninfo WHERE id = '$rowID'";
mysqli_query($con,$sql);
}
break;
