這個問題說明了一切。即使條件得到滿足,代碼仍然沒有運行。如果陳述沒有正確執行,儘管條件得到滿足
我測試了使用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;
}
$ correct_choice和$ selected_choice的實際值是多少? var_dump($ correct_choice)和var_dump($ selected_choice)? – Droid
@Droid可能是問題所在。當我使用var_dump($ correct_choice)和var_dump($ selected_choice),我得到字符串(1)「1」字符串(2)「1;」 – gfcoding
@Droid已解決。這是索引頁面上的語法錯誤。 – gfcoding