鍍金池/ 問答/Java  PHP  數(shù)據(jù)庫/ PHP無法修改數(shù)據(jù)庫數(shù)據(jù)

PHP無法修改數(shù)據(jù)庫數(shù)據(jù)

卡在ERROR報(bào)錯(cuò)一整天了,求大佬們幫幫忙
核心報(bào)錯(cuò)如圖所示:
圖片描述

完整代碼在此:

<?php
header('Content-Type:textml;charset=utf-8');
$username='游客';
//獲取用戶輸入的賬號(hào)和密碼并連接數(shù)據(jù)庫
$account=$_POST['account'];
$password=$_POST['password'];
$db=new mysqli('localhost','root','12345678','newsmanage');
//查詢數(shù)據(jù)庫是否已經(jīng)有相同賬號(hào)
$query1=$db->prepare("SELECT account FROM user");
$query1->bind_result($theaccount);
$query1->execute();
while($query1->fetch()) {
    if ($account == $theaccount) {
        echo '<script>alert("該賬號(hào)已被注冊(cè)!");location.href="register.html"</script>';
        exit();
    }
}
//將用戶輸入的賬號(hào)和密碼寫入數(shù)據(jù)庫
$add=$db->prepare("INSERT INTO user VALUES (null,'general',null,?,?)");
$add->bind_param('ss',$account, $password);
$add->execute();
//數(shù)據(jù)庫對(duì)添加的新用戶自動(dòng)生成唯一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();
//報(bào)錯(cuò)提示:Call to a member function bind_param() on boolean in
echo '<script>alert("恭喜您,注冊(cè)成功!");location.href="../login/login.html"</script>';
回答
編輯回答
痞性

錯(cuò)誤信息已經(jīng)說的很清楚了,說你對(duì)一個(gè)bool值使用了成員函數(shù)。
這個(gè)錯(cuò)誤信息說明你的$db->prepare()方法執(zhí)行失敗了,返回了false,而不是mysqli_stmt對(duì)象。
請(qǐng)確認(rèn)$db是否正確連接,prepare方法中的sql所涉及的表字段名是否有誤。以及其他我暫時(shí)想不到的問題。。。

2017年11月25日 23:24