我插入用户输出如下:
$userName= SanitizeString($userName);
$pass= SanitizeString($pass);
$email= SanitizeString($email);
$userName=mysql_real_escape_string($userName);
$pass=mysql_real_escape_string($pass);
$email=mysql_real_escape_string($email);
$salt = 'SHIFLETT';
$password_hash = md5($salt . md5($pass.$salt));
mysql_query("INSERT INTO users (user_name,pass,email,reputation,role,ban,date) VALUES ('$userName', '$password_hash', '$email', '$reputation', '$role','false','$date')" ) or exit(mysql_error());
这是SanitizeString($ var)函数:
function SanitizeString($var)
{
$var=stripslashes($var);
$var=htmlentities($var, ENT_QUOTES, 'UTF-8');
$var=strip_tags($var);
return $var;
}
但是当我尝试使用此查询查找用户密码和名称时。它失败了:
$user_name=SanitizeString($user_name);
$pass=SanitizeString($pass);
$user_name=mysql_real_escape_string($user_name);
$pass=mysql_real_escape_string($pass);
$salt = 'SHIFLETT';
$password_hash = md5($salt . md5($pass.$salt));
$result=mysql_query("SELECT COUNT(*) AS Result FROM users WHERE user_name='$user_name' AND pass='$password_hash' LIMIT 1") or die(mysql_error());
如果计数大于0意味着它找到了一个结果并且用户应该登录。但是这没有发生..为什么?
更新更多内容:
if(mysql_num_rows($result)>0)
{
echo "Login successful".mysql_num_rows($result);
return $dataArray=TRUE;
}
else
{
echo "Login unsuccessful:".mysql_num_rows($result);
}
答案 0 :(得分:0)
如果您想使用GROUP BY
,则必须使用COUNT(*)
,但您可以获得mysql_num_rows()
这样的行数。
$result=mysql_query("SELECT * AS Result FROM users WHERE user_name='$user_name' AND pass='$password_hash' LIMIT 1") or die(mysql_error());
$num_rows = mysql_num_rows($result);