Rishabh_8 0 Newbie Poster

I have learning this from youtube,php quiz using ajax. I am facing problem when click on next button after last question it is not redirecting on final page.
Please help me to fix this. I think responseText not working.

Question.php page to where i display question

<script type="text/javascript">
var questionno="1";
load_questions(questionno);

function load_questions(questionno){
document.getElementById("current_que").innerHTML=questionno;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                if (xmlhttp.responseText=="over"){
                     window.location="final.php";

            }
            else{
            document.getElementById("load_questions").innerHTML=xmlhttp.responseText;
            load_total_que();
            }
    }
};
xmlhttp.open("GET", "ajax/load_questions.php?questionno="+ questionno,true);
xmlhttp.send(null);
}
</script>

This is the Question_load.php page

<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL); 

?>
<?php
session_start();
include_once("../../configure/config.php");

$question_no="";
$question="";
$opt1="";
$opt2="";
$opt3="";
$opt4="";
$answer="";
$count=0;
$ans="";


$queno=$_GET["questionno"];

if(isset($_SESSION["answer"][$queno]))
{
    $ans=$_SESSION["answer"][$queno];
}

$res=mysqli_query($mysqli,"select * from questions where category='$_SESSION[exam_category]' AND question_no=$_GET[questionno]");

$count=mysqli_num_rows($res);

if($count==0)
{
    echo "over";
}
else
{
    while($row=mysqli_fetch_array($res))
    {
            $question_no=$row["question_no"];
            $question=$row["question"];
            $opt1=$row["opt1"];
            $opt2=$row["opt2"];
            $opt3=$row["opt3"];
            $opt4=$row["opt4"];
    }
    ?>
    <br>

<table>
<h2><?php echo " ( ". $question_no ." ) ". $question; ?></h2>
<table>
<tr>
<input type="radio" name="r1" id="r1" value="<?php echo $opt1; ?>" onclick="radioclick(this.value,<?php echo $question_no; ?>)" 
<?php
if($ans==$opt1){
    echo "checked";
}
?>>
<?php

if(strpos($opt1,'image/')!=false)
{
    ?>
<img src="admin/<?php echo $opt1?>" height="30" width="30">
    <?php
}
else
{
    echo $opt1;
}
?>
</tr>
<br>

<input type="radio" name="r1" id="r1" value="<?php echo $opt2; ?>" onclick="radioclick(this.value,<?php echo $question_no; ?>)" 
<?php
if($ans==$opt2){
    echo "checked";
}
?>>
<?php

if(strpos($opt2,'image/')!=false)
{
    ?>
<img src="admin/<?php echo $opt2?>" height="30" width="30">
    <?php
}
else
{
    echo $opt2;
}
?>
</tr>
<br>
<input type="radio" name="r1" id="r1" value="<?php echo $opt3; ?>" onclick="radioclick(this.value,<?php echo $question_no; ?>)" 
<?php
if($ans==$opt3){
    echo "checked";
}
?>>
<?php

if(strpos($opt3,'image/')!=false)
{
    ?>
<img src="admin/<?php echo $opt3?>" height="30" width="30">
    <?php
}
else
{
    echo $opt3;
}
?>
</tr>
<br>
<input type="radio" name="r1" id="r1" value="<?php echo $opt4; ?>" onclick="radioclick(this.value,<?php echo $question_no; ?>)" 
<?php
if($ans==$opt4){
    echo "checked";
}
?>>
<?php

if(strpos($opt4,'image/')!=false)
{
    ?>
<img src="admin/<?php echo $opt4?>" height="30" width="30">
    <?php
}
else
{
    echo $opt4;
}
?>
</tr>
<br>
</table>
<?php
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.