得到了这个:
public function Register($uname,$pass,$mail)
{
try
{
$new_password = password_hash($pass, PASSWORD_DEFAULT);
$stmt = $this->db->prepare("INSERT INTO users(username,email,password)
VALUES(:uname, :mail, :pass)");
$stmt->bindparam(":uname, $uname");
$stmt->bindparam(":mail, $mail");
$stmt->bindparam(":pass, $new_password");
$stmt->execute();
}
catch (PDOException $e)
{
echo $e->getMessage();
}
}
当我尝试注册它时会抛出一个错误:SQLSTATE [HY093]:参数号无效:没有绑定任何参数。正在通过互联网寻找答案,但还没有找到,也许你们,伙计们,有一些想法?
答案 0 :(得分:2)
您应该使用bindparam(':name', $name)
代替bindparam(':name, $name')
。第一个参数是参数slug的名称,第二个参数是要绑定的变量。
public function Register($uname,$pass,$mail)
{
try
{
$new_password = password_hash($pass, PASSWORD_DEFAULT);
$stmt = $this->db->prepare("INSERT INTO users(username,email,password)
VALUES(:uname, :mail, :pass)");
//note the quotes!
$stmt->bindParam(":uname", $uname);
$stmt->bindParam(":mail", $mail);
$stmt->bindParam(":pass", $new_password);
$stmt->execute();
}
catch (PDOException $e)
{
echo $e->getMessage();
}
}