Hello everyone.. i need help for my project.. im using PHP and MYSQL.. i have an exam in my project where one question is displayed at a time.. the user gets to proceed to another question if he/she gets the right answer for the current question.. otherwise, he/she will be stuck on the same question until he gets it right.. my questions are stored in the database.. and after validation, if the answer is correct, the system is supposed to UPDATE the question number of the current user in the database and will the display the next question.. problem is, i dont know how to display the next question

here's my code:

//this is the part where the question is diplayed
<form name='answer' method='post' action='exam2.php'>
<?php
$query = "Select questionNo from user where name='$_SESSION[user]'";
$result = mysql_query($query) or die('Invalid query'.mysql_error());
$questionNo = mysql_result($result,0);
echo "Question 1:<br>";
$query = "Select question from question where id='$questionNo'";
$result = mysql_query($query) or die('Invalid query'.mysql_error());
$question = mysql_result($result,0);
echo $question;
?>
<br>Answer: <input type='text' size='50' name='answer'>
<br><input type='button' value='Validate Answer'>
</form>


//and this is where the calling of the function for validation of answer is done and is where the updating is suppose to be done if the answer is corret
if(isset($_POST['answer'])){
$answer = $_POST['answer'];
$validateAnswer = validateAnswer($question, $answer);
$n = 1;
		
foreach($validateAnswer as $key => $val){
if($val == "Correct"){
$n++;
$query = "UPDATE user SET questionNo='$n' WHERE name='$_SESSION[user]'";
}else{
echo $val."<br>";
}
}
				
}else{
//no answer provided
}

Updating the question number in the database should do it. At the start of the code your retrieve it, so it should work as it is. I recommend to use this query though:

$query = "UPDATE user SET questionNo = questionNo + 1 WHERE name = '$_SESSION[user]'";
// execute mysql_query here
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.