PHP でクイズを作成していますが、正しい答えが得られると次の質問に進むことができません。私は同じページにとどまりたいです。正解が提出された場合、質問の主キーに 1 を追加しようとしましたが、うまくいかないようです。
<?php
include('includes/config.inc.php');
?>
<?php
if ($_POST==true && array_key_exists('ans', $_POST)){
$ans = $_POST['ans'];
$question = $_POST['question'];
$sql=mysql_query("SELECT * FROM answer WHERE pk_answer = $ans;");
while($row=mysql_fetch_array($sql)){
$correct=$row['correct'];
}
echo $correct;
if ($correct == 1) {
echo "You are so cool!!!!";
} else {
$msg = "You submitted an incorrect answer. Please try again.";
$incorrect = $ans;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>G.A.M.E.</title>
<style>
.incorrect {
color: #F00;
font-weight:bold;
}
</style>
</head>
<body>
<h3>ASTM SAFETY QUIZ QUESTION 1</h3>
<?php
$sql=mysql_query("SELECT * FROM quiz LIMIT 1");
while($row=mysql_fetch_array($sql)){
$pk_quiz=$row['pk_quiz'];
$fk_module=$row['fk_module'];
$fk_task=$row['fk_task'];
$quiz_benchmark=$row['quiz_benchmark'];
$question=$row['question'];
?>
<p><?php echo $question; }?></p>
<form id="quiz" name="form1" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<?php $sql2=mysql_query("SELECT * FROM answer ORDER BY RAND()");
while($row2=mysql_fetch_array($sql2)){
$pk_answer=$row2['pk_answer'];
$fk_quiz=$row2['fk_quiz'];
$answer=$row2['answer'];
$correct=$row2['correct'];
?>
<input type="radio" name="ans" value="<? echo $pk_answer; ?>" id="RadioGroup1_0" />
<?php if ($fk_answer = $pk_quiz) {
if ($incorrect == $pk_answer) {
echo '<span class="incorrect">'.$answer."</span>";
} else {
echo $answer;
}
}}?>
<input name="question" type="hidden" value="<?php echo $pk_quiz; ?>" />
<br /><input name="Submit" type="submit" value="submit" />
</p>
</form>
<?php if ($msg == true) { echo $msg; } ?>
</body>
</html>