所以我试图将用户输入放入数据库。数据库连接正常,但我不知道自己做错了什么。
我的index.php
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Encrypt</h1>
<form action="http://localhost/si/r.php" method="post">
<input type="text" name="encrypt-in">
<input type="submit">
</form>
</body>
</html>
我的r.php
<?php
$con=mysqli_connect("localhost","root","xxx","s");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$password = $_POST['encrypt-in'];
mysqli_query($con,"INSERT INTO pass (Password) VALUES ($password)");
mysqli_close($con);
?>
并且不要担心它不是真正的密码。有任何想法吗?
答案 0 :(得分:0)
mysqli_query($con,"INSERT INTO pass (Password) VALUES ('$password')");
您可能还想包围$ _POST或使用预准备语句。
$password = $con->real_escape_string($_POST['encrypt-in']);