卡在ERROR報錯一整天了,求大佬們幫幫忙核心報錯如圖所示:
完整代碼在此:
<?php
header('Content-Type:textml;charset=utf-8');
$username='游客';
//獲取用戶輸入的賬號和密碼并連接數(shù)據(jù)庫
$account=$_POST['account'];
$password=$_POST['password'];
$db=new mysqli('localhost','root','12345678','newsmanage');
//查詢數(shù)據(jù)庫是否已經(jīng)有相同賬號
$query1=$db->prepare("SELECT account FROM user");
$query1->bind_result($theaccount);
$query1->execute();
while($query1->fetch()) {
if ($account == $theaccount) {
echo '<script>alert("該賬號已被注冊!");location.href="register.html"</script>';
exit();
}
}
//將用戶輸入的賬號和密碼寫入數(shù)據(jù)庫
$add=$db->prepare("INSERT INTO user VALUES (null,'general',null,?,?)");
$add->bind_param('ss',$account, $password);
$add->execute();
//數(shù)據(jù)庫對添加的新用戶自動生成唯一ID,查尋此ID并賦值變量
$query2=$db->prepare("SELECT userid FROM user WHERE account='$account'");
$query2->bind_result($userid);
$query2->execute();
$query2->fetch();
//用username變量修改數(shù)據(jù)表中的數(shù)據(jù)
$edit=$db->prepare("UPDATE user SET username=? WHERE account=?");
$edit->bind_param('ss',$username,$account);
$edit->execute();
//報錯提示:Call to a member function bind_param() on boolean in
echo '<script>alert("恭喜您,注冊成功!");location.href="../login/login.html"</script>';
1 回答

翻過高山走不出你
TA貢獻1875條經(jīng)驗 獲得超3個贊
錯誤信息已經(jīng)說的很清楚了,說你對一個bool值使用了成員函數(shù)。
這個錯誤信息說明你的$db->prepare()
方法執(zhí)行失敗了,返回了false,而不是mysqli_stmt
對象。
請確認$db是否正確連接,prepare方法中的sql所涉及的表字段名是否有誤。以及其他我暫時想不到的問題。。。
- 1 回答
- 0 關注
- 623 瀏覽
添加回答
舉報
0/150
提交
取消