Hello. I have a small problem. I am working on a small website where people will be able to take quizzes for driving lessons. I take my questions and answers from a database. The problem is that i get the first questions and after i submit the answers, the next question won't appear. I don't know what to do. Here is my php code:

<?php
include('db.php');

$query = "SELECT * FROM intrebari";
$exec = mysql_query($query);
$nt = mysql_fetch_array($exec); 
$id = "$nt[id_question]"; 

$currentid = intval($id[0]);
echo "Intrebarea numarul $id";
$next = mysql_query("SELECT id_question FROM intrebari WHERE id_question > $id ORDER BY id_question ASC LIMIT 1");
if (mysql_num_rows($next) > 0){
	$nextid = mysql_result($next, 0);
}

echo "$nextid";

?>

<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php echo "$nt[question]"; ?><br>
<input type="checkbox" name="q1[]" value="a" /><?php echo "$nt[answer_a]"; ?><br>
<input type="checkbox" name="q1[]" value="b" /><?php echo "$nt[answer_b]"; ?><br>
<input type="checkbox" name="q1[]" value="c" /><?php echo "$nt[answer_c]"; ?><br>
<input type="submit" name="id[<?php echo $nextid?>]" value = "Trimite" />
</form>
</body>
</html>


<?php
$rspcorecte = 0;
$rspincorecte = 0;
$corect = "$nt[correct_answer]";
$aux="";

	if(isset($_POST['q1']))
		for($i=0; $i < count($_POST['q1']); $i++)
			$aux=$aux.$_POST['q1'][$i];
if ($aux == $corect) {
	//echo "corect";
	$rspcorecte++;
	header("location: index.php?id=$nextid");
	}
	else{
		$rspincorecte++;
		//echo "gresit";
		//header("location:");
		}
		
?>

and my database table look like this:

CREATE TABLE IF NOT EXISTS `intrebari` (
  `id_question` int(11) NOT NULL AUTO_INCREMENT,
  `question` text NOT NULL,
  `answer_a` text NOT NULL,
  `answer_b` text NOT NULL,
  `answer_c` text NOT NULL,
  `correct_answer` varchar(10) NOT NULL,
  PRIMARY KEY (`id_question`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

Sorry for my bad english, it is not my primary language. Regards, Darius

hey brother you can use ajax using click function.

hey brother you can use ajax using click function.

I am a beginer, so a piece of code would help me alot. Ty in advance.

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.