我正在尝试对用户通行证进行验证。更新代码:
$username="------";
$password="------";
$database="------";
$host = "------";
mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$username = $_POST['username'];
$password = $_POST['password'];
echo 'username: ' . $username . '<br>'; //myname
echo 'password: ' . $password . '<br>'; //mypass
function checkpass()
{
//$result = mysql_query("SELECT * FROM REG_USERS where USERNAME='$_POST[username]' and PASSWORD='$_POST[password]' ") or die(mysql_error());
$result = mysql_query("SELECT * FROM REG_USERS where USERNAME='" . $username . "' and PASSWORD='" . $password . "'") or die(mysql_error());
return mysql_num_rows($result);
}
checkpass();
echo 'checkpass:'. checkpass();
在第一个查询中,checkpass 返回 1。在第二个查询中,它返回 0。为什么?