Click here to Skip to main content
15,877,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a simple quiz in PHP.The user is able to log in.It displays one question per page.Then it goes for review.It allows the user to review one question per page.Each page has a next question button and previous question button(except first page).

Now I wish to retain already selected answers when I tap on previous question.

//code for Next question

if($submit=='Next Question' && isset($ans))
$row= mysql_fetch_row($rs);
mysql_query("insert into mst_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,true_ans,your_ans) values ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());

$_SESSION[yans][$p]=$ans;//$p is $_SESSION[qn]+1


// code for previous question

if($_POST['prev']=='Previous Question')


//code when i Load the quiz
$a = $_SESSION[yans][$p]; // $p = $_SESSION[qn]+1
//echo $p;
echo "Que ". $n .": $row[2]</style>";
echo "<input type=radio name=ans value=1 checked='checked'>$row[3] ";
echo "<input type=radio name=ans value=1>$row[3]";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900