0
我的代码存在一些问题。似乎我无法拥有多个准备好的陈述,这对我来说似乎有点不寻常。在同一页上显示多个预处理语句MYSQLI
我会很高兴,如果你能发现一个错误或帮助我,因为我不知道这个问题。
我的错误:
Fatal error: Call to a member function bind_param() on boolean in /Applications/XAMPP/xamppfiles/htdocs/platform/creating_user.php on line 37
我试图检查用户的电子邮件数据库中已存在,然后注册用户。
代码工作正常,当我不执行$检查。
$check->execute();
我还想对我的工作流程(我的代码的建立方式)做出一些回应。好吗?
谢谢!
<?php
$db = new mysqli("localhost","root","","database");
session_start();
if (isset($_POST)){
if(
!empty($_POST["name"])
& !empty($_POST["city"])
& !empty($_POST["zip"])
& !empty($_POST["email"])
& !empty($_POST["tel"])
& !empty($_POST["password"])
) {
$name = encrypt($_POST["name"]);
$city = encrypt($_POST["city"]);
$zip = encrypt($_POST["zip"]);
$email = encrypt($_POST["email"]);
$tel = encrypt($_POST["tel"]);
$password = encrypt($_POST["password"]);
if(!empty($name) && !empty($city) && !empty($zip) && !empty($email) && !empty($tel) && !empty($password)) {
$check = $db->prepare("SELECT email FROM user WHERE email = ?");
$check->bind_param('s', $email);
$check->execute();
if ($check->num_rows == 1) {
header("Location: index.php");
die();
} else {
$insert = $db->prepare("INSERT INTO user (name, city, zip, email, tel, password, created) VALUES (?, ?, ?, ?, ?, ?, NOW())");
$insert->bind_param("ssssss",$name, $city, $zip, $email, $tel, $password);
if ($insert->execute()){
$db->close();
$_SESSION["user"] = $email;
header("Location: created_user");
die();
} else {
header("Location: create-user");
die();
}
}
} else {
header("Location: create-user");
die();
}
} else {
header("Location: create-user");
die();
}
} else {
header("Location: create-user");
die();
}
?>
'$ DB-> prepare'返回'boolean'这主要是指有一些错误的DB连接。 – WasteD
如果(!$ check = $ db-> prepare(“SELECT email FROM user WHERE email =?”)){ echo $ db-> error; exit(0); } – buildok