遇到了點問題,得不到正確的結(jié)果~~~大神幫忙看下
下面是我的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都沒有錯,數(shù)據(jù)庫里面也是有數(shù)據(jù)的,從login頁面?zhèn)鬟^來的數(shù)據(jù)也能對應(yīng)到數(shù)據(jù)庫里的數(shù)據(jù),dologin執(zhí)行的結(jié)果是0,$mysqli_stmt的內(nèi)容是:
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)
2016-11-09
$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;
這樣就可以
2015-11-30
我估計是你的$username 或者 $password 是字符串,你要用引號來拼接起來,不然會報錯,要不然你就打印出來你的sql語句,拿到數(shù)據(jù)庫去執(zhí)行,你就知道哪里錯了