我有这样的代码:mysqli_num_rows()错误没有返回字符串
$con=mysqli_connect("example","example","example","example");
function check_input($value)
{
global $con;
// Stripslashes
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote if not a number
if (!is_numeric($value))
{
$value = "'" . mysqli_real_escape_string($con, $value) . "'";
}
return $value;
}
$checklogin = mysqli_query($con, "SELECT username, password FROM users WHERE username LIKE '".check_input($_POST['username'])."';");
if(mysqli_num_rows($checklogin) == 0)
{
echo "Username doesn't exist";
}
而且我得到这个错误:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/u436120092/public_html/login.php on line 26 Username doesn't exist
我知道该用户名不存在,但是这不是问题,我经过测试,问题是mysqli_real_escape_string没有返回字符串。
有人可以帮我吗? 在此先感谢。
STOP !!!!您正在使用MySQLi,因此请使用预准备语句/绑定变量。你绝对没有任何借口 – 2014-09-23 14:10:42
你的代码逻辑也是__double__引用字符串值,一旦在check_input()函数中,一次在SQL查询语句中,这会给你一个无效的SQL语句.....这就是你的另一个原因应该使用绑定变量,它会处理所有的字符串引用 – 2014-09-23 14:11:16
您是否选择了数据库? – iatboy 2014-09-23 14:11:30