【发布时间】:2016-05-15 16:51:19
【问题描述】:
我正在使用 php 制作注册表单,但是当我点击注册按钮时,它会在电子邮件和密码字段中保存 1,1 而不是给定的电子邮件和密码。
<?php
include("connection.php")
?>
<?php
$email=isset($_POST['email']);
$password=isset($_POST['password']);
if(isset($_POST['register']))
{
$q= "insert into admin (email, password) values ('$email', '$password')";
$qr=mysqli_query($con, $q);
if($qr)
{
echo "data added sucessfully";
}
else
{
die();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Log in</title>
</head>
<body>
<form method="post" action="">
<input type="email" name="email">
<br>
<input type="password" name="password">
<br>
<button type="submit" name="register" value="register">register</button>
</form>
</body>
</html>
【问题讨论】:
-
php.net/manual/en/function.isset.php , isset 函数返回一个布尔值,更改为 if(isset($_POST['email'])){$email=$_POST['email'];} 编辑:发布为回答
-
请使用 PHP 的built-in functions 来处理密码安全问题。如果您使用的 PHP 版本低于 5.5,则可以使用
password_hash()compatibility pack。