忘记密码脚本PHP mysqli [英] Forgot Password script PHP mysqli

查看:110
本文介绍了忘记密码脚本PHP mysqli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个脚本忘记密码,所以当用户在其中输入电子邮件时,它会验证输入的电子邮件是否与数据库电子邮件一致,如果是,则将确认邮件发送到他的电子邮件地址。
这是正常工作,直到我使用mysql,但转换到mysqli它不工作。当用户在其中输入电子邮件时,它不会发送电子邮件,甚至不会发送电子邮件发送或没有错误。



这是我的Forgot.php脚本(UPDATED SCRIPT AGAIN

 <?php 
error_reporting (0);
if($ _ POST ['submit'] =='Send'){
//保持在
$ email = $ _ POST ['email'];

$ con = mysqli_connect(lovehost,root,123,user);
//检查连接
如果(mysqli_connect_errno()){
echo无法连接到MySQL:。 mysqli_connect_error();
}
$ query = mysqli_query($ con,select * from login where user_email ='$ email')或死(mysqli_error($ con));

$ numrows = $ query-> num_rows();

if($ numrows == 1){
$ code = rand(100,999);
$ message ='你的激活链接是:http://bing.fun2pk.com/forgot.php?email=$email&code=$code';
mail($ email,Subject Goes Here,$ message);
echo'Email sent';
} else {
echo'没有用户存在此电子邮件ID';
}
}
?>
< form action =forgot.phpmethod =post>
输入您的电子邮件ID:< input type =textname =email>
< input type =submitname =submitvalue =发送>
< / form>


解决方案

我想你应该使用
mysqli_num_rows $ query)方法在你的if条件下检查电子邮件是否存在。例如:



如果(mysqli_num_rows($ query)= = 1)
{
//您的邮件方式
}


Hi I am trying to make a script forgot password so when user enter email in it it will verify that if entered email matches the database email if yes then sends confirmation email to his email address. It was working fine untill I was using mysql but after converting it to mysqli it not working. When user enter email in it it does't send email or even it doesn't echo that email sent or no errors.

Here is my Forgot.php script (UPDATED SCRIPT AGAIN)

<?php 
    error_reporting(0);
    if($_POST['submit']=='Send') {
        //keep it inside
        $email=$_POST['email'];

        $con=mysqli_connect("lovehost","root","123","user");
        // Check connection
        if (mysqli_connect_errno()) {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
        $query = mysqli_query($con,"select * from login where user_email='$email'") or die(mysqli_error($con)); 

        $numrows = $query->num_rows();                                  

        if ($numrows == 1) {  
            $code=rand(100,999);
            $message='You activation link is: http://bing.fun2pk.com/forgot.php?email=$email&code=$code';
            mail($email, "Subject Goes Here", $message);
            echo 'Email sent';
        } else {
            echo 'No user exist with this email id';
        }
    }
?>
<form action="forgot.php" method="post">
    Enter you email ID: <input type="text" name="email">
    <input type="submit" name="submit" value="Send">
</form>

解决方案

I think u should use mysqli_num_rows ($query) method inside your if condition to check if email exist or not.

for example:

if (mysqli_num_rows ($query)==1)
{
//your mail method
}

这篇关于忘记密码脚本PHP mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆