这个问题说明了一切。即使满足了这些条件,代码仍然没有运行。
我使用echo测试了正在比较的变量,即使它们是相同的(值为1(,代码仍然没有运行。
我还检查了我的脚本是否有任何语法错误,但没有发现任何错误。
通读stackoverflow没有帮助,因为大多数都与语法错误有关。
无论我做什么,输出仍然是"条件不满足",我可以知道出了什么问题吗?
以下是代码:
<?php
include 'database.php';
if(isset($_POST['submit'])){
$number=$_POST['number'];
$selected_choice = $_POST['choice'];
$next=$number+1;
$query="SELECT* FROM questions";
$results= mysqli_query($con,$query);
$total=$results->num_rows;
$query = "SELECT* FROM `choices` WHERE question_number = $number AND is_correct=1";
$results= mysqli_query($con,$query);
$row=$results->fetch_assoc();
$correct_choice=$row['id'];
if($correct_choice == $selected_choice){
echo "conditions same";
} else{
echo "conditions not same";
}
echo $correct_choice;
echo $selected_choice;
echo $score;
}
已解决,index.php页面中存在语法错误。
当我使用var_dump($correct_choice(和var_dumps($selected_chooce(时,我得到string(1("1"string(2("1;"。
问题在于额外的;
如果If语句内部没有打印出任何内容,那么问题肯定出在表单提交按钮名称中。我相信,提交按钮的代码应该如下所示来解决您的问题-
<input type="submit" name="submit" value="Post your data" class="" />
当然,表单方法应该是POST。看看吧,希望能为你顺利工作。。。