我需要将md5哈希密码发送到数据库。
<?php
$username = filter_input(INPUT_POST, 'name');
$password = filter_input(INPUT_POST, 'password');
print_r($_POST['name']);
if (empty($username)){
echo "Username should not be empty"; die();
}
if (empty($password)){
echo "Password should not be empty"; die();
}
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "db_account";
//create connection
$conn = new mysqli($host, $dbusername, $dbpassword, $dbname);
if (mysqli_connect_error()){
die('Connect Error ('. mysqli_connect_error() .') '
. mysqli_connect_error());
} else{
$sql = "INSERT INTO t_account (name, pwd)
values ('{$username}','MD5({$password})')";
if ($conn->query($sql)){
echo "Account was created successfully!";
}
else{
echo "Error: ". $sql."<br>". $conn->error;
}
$conn->close();
}
?>
当我用123456等密码填写注册表单时,它将像这样(MD5)123456发送到数据库,但不作为哈希码发送。
成功注册后,它仅在@echo之后显示文本,可以将用户重定向到另一页吗?
答案 0 :(得分:0)
尝试使用PHP md5()函数:
$password = md5(filter_input(INPUT_POST, 'password'));
您的声明:
$sql = "INSERT INTO t_account (name, pwd)
values ('{$username}','{$password}')";
我强烈建议您使用准备好的语句。不难学习,花时间进行充分的投资。