我对PHP和MySQL相当陌生。我正在尝试在表单提交后插入数据。
mysqli_stmt_prepare()不起作用,我知道它很简单,但是我无法弄清楚。当我在上一页中单击“提交”时,它进入此页面,但没有将字段输入数据库。
<?php
include_once("../core/database/connection.php");
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
$userName = $_POST["userName"];
$password = password_hash($_POST["password"], PASSWORD_DEFAULT);
$sql = "INSERT INTO users (firstName, lastName, email, userName, password) VALUES (?, ?, ?, ?, ?);";
$post_stmt = mysqli_stmt_init($connect);
if(mysqli_stmt_prepare($post_stmt, $sql))
{
mysqli_stmt_bind_param($post_stmt, "sssss", $firstName, $lastName, $email, $userName, $password);
mysqli_stmt_execute($post_stmt);
echo "You have been successfully registered!";
}
else
{
die('Error with execute: ' . htmlspecialchars($post_stmt->error));
}
?>