我正在使用 PHP 插入 MySQL,代码通过,但是当我查询数据库时,我的数据库中什么也没有。我无法弄清楚发生了什么。我的数据库中有五个字段(ID、用户名、电子邮件、密码、盐)。下面是我的 PHP 代码。
<?php
include 'db_connect.php';
include 'functions.php';
$password = $_POST['password'];
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
$password = hash('sha512', $password.$random_salt);
if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email,
password,salt) VALUES (?, ?, ?, ?)"))
{
$insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
$insert_stmt->execute();
echo 'User added';
}
else
{
echo 'Error couldnt add the user, Try again';
}
?>
以下是我用于注册的表格。
<form id="form1" name="form1" method="post" action="Registration Process.php">
<table width="373" height="130" border="1">
<tr>
<td width="180" height="27">Username (Name & Surname)</td>
<td width="140"><label for="username"></label>
<input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td height="23">Email</td>
<td><label for="email"></label>
<input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td height="22">Password</td>
<td><label for="password"></label>
<input type="text" name="password" id="password" /><label for="salt"> </label> </td>
</tr>
<tr>
<td height="22">Salt</td>
<td><input type="text" name="salt" id="salt" /></td>
</tr>
<tr>
<td height="22">Click To register member</td>
<td><input type="submit" name="register" id="register" value="Submit" /></td>
</tr>
</table>
<p> </p>
<!-- end .content -->
</form>