我已经制作了忘记密码脚本,用户将被重定向到另一个页面&他需要输入他的电子邮件ID。如果存在电子邮件ID,则将详细信息发送到该特定电子邮件ID。如果没有,则给出错误消息。如果电子邮件字段为空,则无法收到错误消息&按下提交
请帮助!
<?php
$email="";
$emailErr="";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["email"]))
{
$emailErr = "Email is required";
}
else
{
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid email format";
}
}
if($_POST['submit']=='Send')
{
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="testmra"; // Database name
// Connect to server and select databse.
$conn=mysqli_connect($host,$username,$password) or die("cannot connect");
mysqli_select_db($conn,$db_name);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$query="select * from newuser where emailid='$email'";
$result=mysqli_query($conn,$query) or die('Error: Cannot connect to db' );
if(mysqli_num_rows($result))
{
$subject="Testing";
$message="Hello Testing";
mail($email, $subject, $message);
}
else
{
$emailErr = "No user exist with this email id";
}
}
}
?>
<html>
<head><title>MRA</title></head>
<body>
<form method="post">
<table align="center">
<tr><td align="right">Email Id :</td><td><input type="text" name="email" value="<?php if (isset($_POST["email"])) { echo $_POST["email"];}?>"></td><td align="left"><input type="submit" name="submit" value="Send"></td></tr>
<tr><td colspan="3" align="center"><font color="red"><?php echo $emailErr; ?></td></tr>
</table>
</form>
</body>
</html>
答案 0 :(得分:2)
根据您提供的错误,更改此行
$query=mysqli_query($conn,"select * from newuser where emailid='$email'");
对此:
$query="select * from newuser where emailid='$email'";
我假设第31行...查询必须是字符串,而不是对象。
答案 1 :(得分:0)
尝试使用随机令牌(例如example.com/reset_password?token=wecmwkwc321k3m1k2)向用户发送链接,将令牌暂时保存在数据库中,当用户点击链接匹配令牌并将用户发送到重置密码的页面时...
答案 2 :(得分:0)
请更改您的连接:
$conn=mysqli_connect($host,$username,$password) or die("cannot connect");
mysqli_select_db($conn,$db_name);
为:
$conn = mysqli_connect($host,$username,$password,$db_name) or die("cannot connect");
比以下更改查询:
$query=mysqli_query($conn,"select * from newuser where emailid='$email'");
$result=mysqli_query($conn,$query) or die('Error: Cannot connect to db' );
到:
$query=mysqli_query("select * from newuser where emailid='$email'", $conn) or die('Error: Cannot connect to db' );