如何提交答案并检查答案是否与数据库表php mysql中的答案相同?

时间:2017-11-09 08:51:44

标签: php mysql database

$answers = ambilJawabanUSER($simpanID,$conn); // function to save the answer from database table
$userAnswer = $_POST['answers'];

foreach( $userAnswer as $getAnswer ) {
   if ($userAnswer == $answers){
      echo "correct";
else{
echo "wrong";
}
}

我的代码与上面的代码类似,但它在我的情况下不起作用。有人有解决方案吗?

1 个答案:

答案 0 :(得分:0)

我认为您在代码中有一个错误。你应该尝试这个代码

$answers = ambilJawabanUSER($simpanID,$conn); // function to save the answer from database table
$userAnswer = $_POST['answers'];

foreach( $answers as $getAnswer ) {
   if ($userAnswer == $getAnswer){
      echo "correct";
}else{
echo "wrong";
}
}