I cant update the corresponding edited items. Only the first questions and answers are being updated. I cant get the result that I want. Im stuck on this for a day. Please help me.
Heres the scenario: I have a php file that contains the form and passes it to another php file. a checkbox that has the question id and textboxes that allows them to edit their questions from the database. Every question has its corresponding answers. Also, they can edit them. If they click update button all of the checked questions should be updated. but not all of them is updated. Literally only the first question is the only item that can be updated. Anyone knows whats wrong with my code??
heres a link for the screenshot http://imageshack.us/photo/my-images/706/cetw.png/
Heres my code:
$selected = $_POST['selected'];///the checkbox
$question = $_POST['questiondesc'];
for ($i = 0; $i < sizeof($selected); $i++)
{
$sql = sprintf("UPDATE exam_questions SET question_description = '%s' WHERE question_id = '%s'",
mysql_real_escape_string($question[$i]),
mysql_real_escape_string($selected[$i]));
mysql_query($sql)or die(mysql_error());
$eren = mysql_query("SELECT * FROM exam_answers WHERE answer_question_set_id = '".$selected[$i]."'")or die(mysql_error());
while($mikasa = mysql_fetch_array($eren)){}
$count = mysql_num_rows($eren);
$answer = $_POST['answerdesc'];
$answerid = $_POST['ansid'];///answer id
for($e = 0; $e<$count; $e++){
$gomugomu = sprintf("UPDATE exam_answers SET answer_description = '%s' WHERE answer_id = '%s'",
mysql_real_escape_string($answer[$e]),
mysql_real_escape_string($answerid[$e]));
mysql_query($gomugomu)or die(mysql_error());
}