我的网站上有一个用户创建表单,它无法将任何新用户数据添加到相关的 MySQL 表中。我真的不太清楚为什么它没有添加数据,也没有抛出任何错误来告诉我出了什么问题。
我目前有以下用户创建表单:
<form name="adduser_form" action="process/adduser_process.php" method="post">
Username:<input id="username" type="test" name="username" />
Email:<input id="email" type="text" name="email" />
Password:<input id="password" type="password" name="password" />
<input id="add_usr" type="button" value="Add User" onclick="formhash(this.form, this.form.password);" />
</form>
单击“添加用户”按钮后,formhash JS 会创建一个散列密码,然后将表单提交到 adduser_process.php:
function formhash(form, password) {
var p = document.createElement("input");
form.appendChild(p);
p.name = "p";
p.type = "hidden";
p.value = hex_sha512(password.value);
password.value = "";
form.submit();
}
adduser_process.php 的工作方式如下(故意省略标签):
include '../includes/lgn_connect.php';
include '../includes/functions.php';
sec_session_start();
$password = $_POST['p'];
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
$password = hash('sha512', $password.$random_salt);
if($insert_stmt = $mysqli->prepare("INSERT INTO users (username, email, password, salt) VALUES (?, ?, ?, ?)")) {
$insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
$insert_stmt->execute();
}