我真的很难弄清楚为什么if(isset($_POST['next']))
不起作用。我怎样才能在函数中调用类似的东西?
function questions($result){
$options = array('A','B','C','D','E');
echo "Please click 'Next'";
echo "<p class = 'button'><input type='submit' name='next' value='Next'/></p>";
while($row = $result->fetch_assoc()){
if(isset($_POST['next'])) {
echo "<h4>".$row['question']."</h4>";
foreach($options as $option){
$text = $row[$option];
if($text)
echo "<br/><input type = 'radio' name = 'ans' value = '$option'>".$text."<br/>";
}
echo "<p class = 'button'><input type='submit' id='submit' class = 'answer' name='submitAns' value='Submit' /></p>";
if(isset($_POST['submitAns'])){
$answer = $row['answer'];
if($_POST('ans') == $answer) {
echo "<h4>Correct!</h4>";
} else {
echo "<h4>Incorrect. Correct answer is: ".$answer."</h4>";
}
echo "<p class = 'button'><input type='submit' id='next' name='next' class = 'answer' value='Next' /></p>";
}
}
}
if(isset($_POST['next'])){
echo "End of questions for this exam";
}
}