【问题标题】:Forgot Password script PHP mysqli忘记密码脚本 PHP mysqli
【发布时间】:2013-12-02 12:28:30
【问题描述】:

您好,我正在尝试制作一个忘记密码的脚本,因此当用户在其中输入电子邮件时,它将验证输入的电子邮件是否与数据库电子邮件匹配,如果是,则将确认电子邮件发送到他的电子邮件地址。 在我使用 mysql 之前它工作正常,但在将其转换为 mysqli 后它无法正常工作。当用户在其中输入电子邮件时,它不会发送电子邮件,甚至不会回显发送的电子邮件或没有错误。

这是我的 Forgot.php 脚本(更新的脚本再次

<?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>

【问题讨论】:

  • 只检查 $numrows 的值
  • 我同意 Rishabh 的观点。问题似乎在于 num 行。我也遇到了 ->num_rows() 命令的问题。也许使用 sql 限制或尝试程序样式:mysqli_num_rows

标签: php mysql email mysqli


【解决方案1】:

我认为你应该使用 if 条件中的 mysqli_num_rows ($query) 方法检查电子邮件是否存在。

例如:

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

【讨论】:

    【解决方案2】:

    如果我没看错,则未设置 $_GET['ID'],因为您将表单提交给 forgot.php,但没有名为 ID 的 GET 值

    【讨论】:

      【解决方案3】:

      我尝试在我的网站中使用测试来解决此问题,您的代码应该是这样的 即使有很多错误,并且您的数据库很容易被匿名用户“入侵”,仍然只是为了显示问题。 Forgot.php

      <?php 
          error_reporting(0);
          require('includes/db.php');
          if (isset($_POST['email'])) {
              $email = $_POST['email'];
              $code = rand(100,999);
              $query = "SELECT * FROM `users` WHERE email = '$email'";
              $result = mysql_query($query) or die(mysql_error());
              $count = mysql_num_rows($result);
      
              if ($count == 1) {
                  mysql_query("update users set activation_code='$code' where email='$email'");
                  //That Mail code should be put here    <----------------------
              } else {
              }
              echo " Something Here for a response";
          }
      ?>
      
      <form action="" method="post">
          Enter you email ID: <input type="text" name="email">
          <input type="submit" name="submit" value="Send">
      </form>
      

      这在我测试后有效:/

      【讨论】:

        猜你喜欢
        • 2013-12-18
        • 2014-09-02
        • 2013-08-22
        • 2015-04-17
        • 2011-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多