我有一个 php 脚本,带有 if 和 else 块。两者都只包含 echo 语句。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?';
?>