我有一個PHP腳本,與if和else塊。兩者都只包含回聲。 if塊可以完美地執行,但是當else塊什麼都不執行時會被打印到屏幕上(甚至不在塊外部的echo語句)。我已經嘗試了很多東西,例如大寫ELSE語句,檢查所有大括號,雙重和三重檢查語法無濟於事。請幫忙。其他塊不執行
<?php
// Inialize session
session_start();
// Include database connection settings
include('config.inc');
$usr = mysql_real_escape_string($_POST['****ID']);
// Retrieve email address and message from database according to user's input
$query = "SELECT * FROM users WHERE username = '$usr'";
$result = mysql_query($query) or die(mysql_error());
// Put the id numbers in array $row
$row = mysql_fetch_array($result) or die(mysql_error());
// Test for ID match
if (mysql_num_rows($result) == 1)
{
echo 'The email address of ';
echo $usr;
echo ' is: ';
echo $row['email'];
echo '<p>Message: ';
echo $row['firstname'];
}
else
{
echo 'Sorry it appears that ';
echo '$usr';
echo ' has not registered yet. Why dont you tell him about ****Jacker?';
}
// Executing outside if..else blocks for testing
echo 'Sorry, it appears that ';
echo '$usr';
echo ' has not registered yet. Why dont you tell him about ****Jacker?';
?>
在'if()'前面加上'var_dump(mysql_num_rows($ result))',看看這個值是什麼,也許'mysql_num_rows($ result)'的結果'你的想法是什麼? – Jelmer
聽起來像是一個解析器錯誤,你可以運行相同的腳本,其前綴爲'error_reporting(-1)'前綴爲 – raina77ow
,否則你可以執行'if(false)'到確保它進入else語句,看看它是什麼... – Mathlight