php - MySQL statement seems to have an error. I get mysqli_num_rows() and mysqli_fetch_array() errors -


i've been working on password reset form. sql statement seems returning nothing. i've removed sections of code simplify it, can't seem pasted mysqli_num_rows(). think there wrong mysqli_query() statement on line proceeding it. i've try using mysql_num_rows , mysql_query alternative.

<?php if(isset($_post["u"])) { // connect database     include_once("includes/connect.php");  // gather posted data local variables , sanitize      $u = preg_replace('#[^a-z0-9_]#i', '', $_post['u']);              $e = mysql_real_escape_string($connect, $_post['e']);  $username = $_post['username']; $email = $_post['email'];  $query = mysqli_query($connect, "select username, email users username='$username'"); $numrows = mysqli_num_rows($query); if($numrows > 0)         {     while($row = mysqli_fetch_array($query, mysqli_assoc)){          $db_u = $row["username"];                     $db_e = $row["email"];     }                 if($e == $db_e && $u == $db_u)                 {         $code = rand(10000,9999999);          $sql = "update users set passreset='$code' username='$username'";         $query = mysqli_query($connect, $sql);                      $to = $db_email;         $subject = "password reset";         $body = "this automated email           ";           mail($to,$subject,$body);          echo "success";              }  else {  echo"no_exist";  exit();   } } } ?>    <script> function forgotpass(){     var u = _("username").value; var e = _("email").value; if(e == "" || u == ""){     _("status").innerhtml = "this form requires enter both username , email."; } else {     _("forgotpassbtn").style.display = "none";     _("status").innerhtml = 'please wait ...';     var ajax = ajaxobj("post", "forgot.php");     ajax.onreadystatechange = function() {         if(ajaxreturn(ajax) == true) {             var response = ajax.responsetext;             if(response == "success"){                 _("forgotpassform").innerhtml = '<h3>check email inbox </h3>';             } else if (response == "no_exist"){                 _("status").innerhtml = "email address not found";             } else if(response == "email_send_failed"){                 _("status").innerhtml = "mail function failed execute";             } else {                 _("status").innerhtml = "an unknown error occurred";             }         }     }     ajax.send("e="+e+"&u="+u); } } </script> </head> <body>     <h3>reset password</h3>  <form id="forgotpassform" onsubmit="return false;">  <div>enter username</div> <input id="username" type="text" onfocus="_('status').innerhtml='';" maxlength="88">   <br /><br />  <div>enter email address</div> <input id="email" type="text" onfocus="_('status').innerhtml='';" maxlength="88"> <br /><br />  <button id="forgotpassbtn" onclick="forgotpass()">submit</button>  <p id="status"></p>  </form>   </div>      </body>     </html> 

value variable $e might problem using mysql escape 2 variables , change mysqli escape


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -