我正在研究一个我认为很简单的脚本,当用户填写我的在线表格时将其添加到数据库中,但我正在尝试散列密码,一旦我填写了表格,我就会收到一个 PHP 错误。如果有人可以提供帮助,我将添加我的代码,将不胜感激:)
<?php
// Set up database connection
$host = "localhost";
$username = "root";
$password = "";
$dbname = "UsersNextcloud";
$conn = new mysqli($host, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = $_POST['Username'];
$Display = $_POST['Display_Name'];
$password = $_POST['Password'];
$email = $_POST['Email'];
$quota = $_POST['Quota'];
$hashed = password_hash($password, PASSWORD_DEFAULT);
$stmt = $conn->prepare("INSERT INTO Connect (Username, Display_Name, Password, Email, Quota) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $name, $Display, $hashed, $email, $quota);
if ($stmt->execute()) {
echo "Data inserted successfully.";
} else {
echo "Error inserting data: " . $stmt->error;
}
// Close database connection
$stmt->close();
$conn->close();
?>
`