Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:08:51+00:00 2026-06-15T18:08:51+00:00

I got a piece of code below where it performs certain php/mysqli tasks on

  • 0

I got a piece of code below where it performs certain php/mysqli tasks on validation and success. The problem I am having with the code below is that if the user enters in an incorrect username or email which is determined by a SELECT query, if there is no matching username and email then it should display the error message Your Username or Email was not Correct. But instead it is displaying this error message An error has occured, your Email was not sent containing your new Password.

My question is that why is it displaying the incorrect error message and how can I get it to dispaly the correct error message?

            if(isset($_POST['resetbtn'])){
                //get form data
                $user = $_POST['user'];
                $email = $_POST['email'];

 $errors = array();


if(!$errors) {

            $query = "SELECT TeacherUsername, TeacherEmail FROM Teacher WHERE TeacherUsername = ? AND TeacherEmail = ?";
            // prepare query
            $stmt=$mysqli->prepare($query);
            // You only need to call bind_param once
            $stmt->bind_param("ss",$user, $email);
            // execute query
            $stmt->execute(); 
            // get result and assign variables (prefix with db)
            $stmt->bind_result($dbTeacherUsername, $dbTeacherEmail);
            //get number of rows
            $stmt->store_result();
            $numrows = $stmt->num_rows();                                  

            if ($numrows == 1){

                   $pass = rand();
                   $teacherpassword = md5($pass);
                   $teacherpassword = substr($pass, 0, 15);
                   $teacherpassword = md5(md5("g3f".$pass."rt4")); 

                //update password in db   
                $updatesql = "UPDATE Teacher SET TeacherPassword = ? WHERE TeacherUsername = ?";                                            
                $update = $mysqli->prepare($updatesql);
                $update->bind_param("ss", $teacherpassword, $user);
                $update->execute();

            $query = "SELECT TeacherUsername, TeacherPassword FROM Teacher WHERE TeacherUsername = ? AND TeacherPassword = ?";
            // prepare query
            $stmt=$mysqli->prepare($query);
            // You only need to call bind_param once
            $stmt->bind_param("ss",$user,$teacherpassword);
            // execute query
            $stmt->execute(); 
            // get result and assign variables (prefix with db)
            $stmt->bind_result($dbTeacherUsername, $dbTeacherPassword);
            //get number of rows
            $stmt->store_result();
            $selectnumrows = $stmt->num_rows();

                            }else{
                        if(!$numrows){
                        $errormsg = "Your Username or Email was not Correct"; 
                        $user = "";
                        $email = "";
                    }
                }
        }


        if(empty($errors)) {
            if ($selectnumrows == 1){


                   $errormsg = "<span style='color: green'>Your Password has been Reset. An Email has been sent with your New Password</span>";


                    else{
                     $errormsg = "An error has occured, your Email was not sent containing your new Password";   

               }
           }

Below is the form:

            echo "<form action='./forgotpass.php' method='post'>
            <table>
            <tr>
            <td></td>
            <td id='errormsg'>$errormsg</td>
            </tr>
            <tr>
            <td>Username</td>
            <td><input type='text' name='user' value='$user'/><br/>".$error_user."</td>
            </tr>
            <tr>
            <td>Email</td>
            <td><input type='text' name='email' value='$email'/><br/>".$error_email."</td>
            </tr>
            <tr>
            <td></td>
            <td><input type='submit' name='resetbtn' value='Reset Password' /></td>
            </tr>
            </table>
            </form>";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:08:53+00:00Added an answer on June 15, 2026 at 6:08 pm

    What happens is that if $query returns no rows, first your $errormsg becomes “Your Username or Email was not Correct” and after that it changes to: “An error has occured, your Email was not sent containing your new Password”.

    The conditions are exactly the same (same query!), so if the first is true then the second one will be true as well. I’m not sure why you need two identical queries, but if you indeed need it, try changing the $errormsg variables in the last few lines to another variable (e.g. $errormsg2) and echoing them separately in the form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a piece of code that works fine. It basically loops through each
I have got a piece of code, that should countdown some number (in this
I've got this piece of code in my jquery validation script: resetForm: function() {
I got the below piece of code and it keeps on printing the frequency
I am trying to compile this piece of code found below. However, I got
Problem in brief I have got a piece of working two dimensional scrolling code.
I've got a piece of code that I can't figure out how to unit
So I've got this piece of code below: var divs = [A, B, C];
I've got a short piece of code that originally created an SqlDataAdapter object over
I have a piece of code that in principal looks like the below. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.