我有一个工作INSERT语句,允许访问者在我的网站上创建一个帐户。
我正在尝试创建一个SELECT语句来检查他们尝试注册的用户名是否存在。出于某种原因,当SELECT语句运行时,我在INSERT语句上得到Call to a member function bind_param() on boolean
(第29行)。
这是为什么?我提供了我的代码......
<?php
require '../manager-session.php';
require '../../db-config.php';
require '../../distributor-config.php';
$role = 'User';
$title = $_POST['title'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$company = $_SESSION['userinfo']['company'];
$emailaddress = $_POST['emailaddress'];
$telephone = $_POST['telephone'];
$addressline1 = $_POST['addressline1'];
$addressline2 = $_POST['addressline2'];
$addressline3 = $_POST['addressline3'];
$towncity = $_POST['towncity'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$username = $_POST['username'];
$password = $_POST['password'];
$stmt_check = "SELECT username FROM users WHERE username = ?";
$stmt_check = $conn->prepare($stmt_check);
$stmt_check->bind_param('s', $_POST['username']);
$stmt_check->execute();
if($stmt_check == true) {
$stmt = $conn->prepare("INSERT INTO users (role, distributor, company, title, firstname, surname, emailaddress, telephone, addressline1, addressline2, addressline3, towncity, county, postcode, username, password) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssssssssssss", $role, $distributor, $company, $title, $firstname, $surname, $emailaddress, $telephone, $addressline1, $addressline2, $addressline3, $towncity, $county, $postcode, $username, $password);
$stmt->execute();
$to = "". $emailaddress ."";
$subject = "New User Account";
$txt = "". $firstname ." ". $surname ." has created a new User account for ". $distributor .". Please login using the following details:\n\nUsername: ". $username ."\nPassword: ". $password ."";
$headers = "From: removed@email.com" . "\r\n" . "BCC: removed@email.com, removed@email.com ". $distributoremail ."";
mail($to, $subject, $txt, $headers);
header('location: ../add-a-new-user.php?page=add-a-new-user&status=success');
exit();
}
else {
header('location: ../add-a-new-user.php?page=add-a-new-user&status=error');
exit();
}
$stmt->close();
$conn->close();
?>
答案 0 :(得分:0)
mysqli->prepare
返回false。这可能是由于SQL语法错误或其他SQL错误。
编辑: 您显然可以获得这样的预准备语句错误:
$stmt = $conn->stmt_init();
$stmt->prepare("...");
var_dump($stmt->error);