qq_BeyonceInt_0
2015-11-29 21:56
下面是我的dologin.php的代码
header("content-type:text/html;charset=utf-8");
$mysqli = new mysqli('localhost','root','','test');
$mysqli->set_charset('utf8');
if ($mysqli->connect_errno)
{
die($mysqli->error);
}
$username = $_POST['username'];
$password = md5($_POST['password']);
$sql="SELECT * FROM test01 WHERE username=? and password=?" ;
$mysqli_stmt=$mysqli->prepare($sql);
$mysqli_stmt->bind_param('ss', $username, $password);
$con = $mysqli_stmt->execute();
echo $mysqli_stmt->num_rows;
print_r($mysqli_stmt);
sql和$con都没有错,数据库里面也是有数据的,从login页面传过来的数据也能对应到数据库里的数据,dologin执行的结果是0,$mysqli_stmt的内容是:
mysqli_stmt Object( [affected_rows] => -1 [insert_id] => 0 [num_rows] => 0 [param_count] => 2 [field_count] => 4 [errno] => 0 [error] =>
[sqlstate] => 00000 [id] => 1)
$sql="select * from user where username=? and password=?";
$res=$mysqli->prepare($sql);
$res->bind_param('ss',$username,$password);
$res->execute();
$res->store_result();
echo $res->num_rows;
exit;
这样就可以
我估计是你的$username 或者 $password 是字符串,你要用引号来拼接起来,不然会报错,要不然你就打印出来你的sql语句,拿到数据库去执行,你就知道哪里错了
Duang~MySQLi扩展库来袭
28643 学习 · 181 问题
相似问题