我正在使用PHP插入MySQL,代码经历但是当我查询数据库时,我在我的数据库中找不到任何内容。我无法弄清楚发生了什么。我的Db中有五个字段(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>
答案 0 :(得分:1)
您的代码可能无法从$username
数组中获取$email
,POST
和其他变量。
此外,您还没有在$insert_stmt->execute()
函数中发现错误 - see example 3 on this page以获取更多信息。