【发布时间】:2013-03-30 12:36:58
【问题描述】:
我的问题是:
<?php
function user_exists($username) {
$username = sanitize($username);
return (mysql_result(mysql_query("SELECT_COUNT('user_id') FROM `user` WHERE `username` = '$username'"), 0) == 1) ? true : false;
}
?>
如您所见,我已包含正确的数据库名称并且用户确实存在,这就是我调用它从 sql 中提取的位置:
<?php
include 'core/init.php';
if (user_exists('dan') === true) {
echo 'exists';
}
die();
if (empty($_POST) === false) {
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username) === true || empty($password) === true {
$errors[] = 'You need to enter a username and password';
} else if (user_exists($username) === false) {
$errors[] = 'Sorry this user does not exist';
}
}
?>
我不知道为什么我得到一个空白页面并且它显示的是用户存在的消息?
【问题讨论】:
-
不鼓励在 PHP 中使用
mysql_*函数,而建议使用 PDO 或 MySQLi (find out why) -
什么是 die();在公开场合做什么? ;)
-
@dbf - 这个功能现在已经被取消了,但我仍然得到空白页