【发布时间】:2019-07-03 14:34:39
【问题描述】:
我准备好的语句的当前语法不正确,其中我:(INSERT...?, ?, ?)
我尝试从不同的示例中复制语法,但似乎我尝试的次数越多,我的登录系统就越崩溃。 我有一些相互矛盾的例子,不确定哪种语法是正确的。我需要在 INSERT 之前使用 $stmt = $conn->prepare 吗?
// create preprepared statement
$sql = "INSERT INTO `user` (username, password, email) VALUES (?, ?, ?)";
// check if sql statement is correct
if ($stmt = mysqli_prepare($connection, $sql)) {
// Add the variables to the stmt
mysqli_stmt_bind_param($stmt, "sss", $param_username, $param_hashed_password, $param_email);
$param_username = $username;
$param_password = $hashed_password;
$param_email = $email;
// Attempt to execute the stmt
if(mysqli_stmt_execute($stmt)) {
// If statement executed
$_SESSION["username"] = $username;
header("location: login.php");
目前它没有向我的数据库中插入任何值,并且用户注册失败。
编辑:
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
我突然想到这可能是密码哈希的错误使用?
【问题讨论】:
-
$param_hashed_passwor!=$param_password -
你在你的绑定语句之后定义了你的参数。
-
@user9189147 - 在
mysqli这样做很好 -
啊,感谢您指出这一点,但修复错字后仍然出现相同的错误。
-
@JoeS。你得到什么错误?
标签: php mysqli prepared-statement