//function to add bm
function add_bm($new_url, $email)
{
$db = $this->dbm;
$this->new_url = $new_url;
$this->email = $email;
$sql = "select * from bookmark where email='$this->valid_user' and bm_URL='$this->new_url'";
if(!$stmt = $db->conn->query($sql))
{
echo "query failed: (" . $db->conn->errno . ") " .$db->conn->error;
}else{
//echo "can check";
//return true;
//row count
if($stmt->num_rows > 0){
echo "<b><br>Sorry ! <br> The URL had already been added . </b> ";
return false;
}else{
//return true;
// prepare and bind
$stmt = $db->conn->prepare("INSERT INTO bookmark (email, bm_URL,) VALUES (?,?)");
$stmt->bind_param("ss", $this->email, $this->new_url);
// set parameters and execute
if($stmt->execute()){
$stmt->close();
$db->conn->close();
return true;
}
}
}
}
答案 0 :(得分:0)
执行数据库操作时,请在继续之前检查错误。否则你会得到意想不到的行为和令人费解的错误,比如这个。
$stmt->bind_param
因$stmt===false
而无效,因为前一条指令有误。
if(!$stmt = $db->conn->prepare("INSERT INTO ...")){
//something went wrong. This shows the error but handle as appropriate
die($db->$conn->error);
}
//safe to continue
$stmt->bind_param(...)