失败的bind_param是这样的
$stmt->绑定参数(‘sss’,$this->模板->表单->注册表用户名,$this->模板->表单->注册表密码,$this->模板->表单->reg_email,“测试”);
准备好的语句是
$stmt = $this->mysqli->prepare("INSERT INTO 'users‘(username,password,email,referr) VALUES (?,?)");
整个注册函数是
public function Register() {
unset($this->template->forms->error);
$this->template->forms->setData();
if(isset($this->template->forms->submit)) {
if(!isset($this->template->forms->reg_username)) {
$this->template->forms->error = "You must enter an username";
}
if(!isset($this->template->forms->reg_password)) {
$this->template->forms->error = "You must enter a password";
}
if(!isset($this->template->forms->reg_password_confirm)) {
$this->template->forms->error = "You must confirm your password";
}
if(!isset($this->template->forms->reg_email)) {
$this->template->forms->error = "You must enter an email address";
}
if($this->template->forms->reg_password != $this->template->forms->reg_password_confirm) {
$this->template->forms->error = "Your passwords must match";
} else if(strlen($this->template->forms->reg_password) <= 5) {
$this->template->forms->error = "Your password must be 6 characters or more.";
}
if(!$this->template->forms->error) {
$stmt = $this->mysqli->prepare("INSERT INTO 'users' (username, password, email, referr) VALUES (?, ?, ?, ?)");
$stmt->bind_param('ssss', $this->template->forms->reg_username, $this->template->forms->reg_password, $this->template->forms->reg_email, "Adam");
$stmt->execute();
}
}
}
发布于 2013-12-28 22:31:54
您的MySQL查询中存在错误。如果无法创建预准备语句,则prepare()
方法将返回false
。来自prepare()
方法的文档:
返回值
如果发生错误,mysqli_prepare()
将返回一个statement对象或FALSE
。
错误消息将存储在MySQLi连接对象的error
field中。在尝试发送查询或创建预准备语句时,请始终添加错误处理。
发布于 2018-07-10 04:03:21
我相信你的SQL中有一个错误,@Progman在他的回答中指出了这一点。我认为错误是你有‘用户’,而它应该是users
,这可能会导致它失败。将您的SQL更改为我在下面提供的SQL,并让我知道它是否有效。
INSERT INTO `users` (username, password, email, referr) VALUES (?, ?, ?, ?)
https://stackoverflow.com/questions/20813722
复制相似问题