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 8344237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:18:03+00:00 2026-06-09T06:18:03+00:00

I am using mysqli and php and what I am trying to do is

  • 0

I am using mysqli and php and what I am trying to do is that I want the user to be able create a new password if they wish to do this.

For a user to change their password, the will enter in their username in the “Username” textbox and then type in their new password in the “New Password” textbox.

When the user submits the form, it should look in the database, find the username which matches in the database and update that row so the previous password changes to a new password and it also salts the password for better encryption.

But the problem is that it is not doing this at all. The database is not updating the password at all, never mind salting them and I can’t figure out what I need to do.

Below is my attempt (I have connected to db but just not included that code below):

     <?php
          // PHP code
          session_start(); 

          $salt = ""; 
        for ($i = 0; $i < 40; $i++) { 
           $salt .= substr(
             "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 
             mt_rand(0, 63), 
             1); 
        }


          $username = (isset($_POST['username'])) ? $_POST['username'] : '';
          $newpassword = (isset($_POST['newpassword'])) ? $_POST['newpassword'] : '';

          if (isset($_POST['submit'])) {

            // don't use $mysqli->prepare here
     $query = "UPDATE Teacher SET TeacherSalt = $salt, TeacherPassword = SHA1(CONCAT($newpassword,$salt)) WHERE TeacherUserName = ?";
            // prepare query
            $stmt=$mysqli->prepare($query);
            // You only need to call bind_param once
            $stmt->bind_param("s",$username);
            // execute query
            $stmt->execute(); 
            // get result and assign variables (prefix with db)
            $stmt->bind_result($dbTeacherUsername,$dbTeacherPassword);

            while($stmt->fetch()) {
              if ($username == $dbTeacherUsername) {
                $loggedIn = true;
              }
            }

            /* close statement */
            $stmt->close();

            /* close connection */
            $mysqli->close();


          }

....

          <p>Username</p><p><input type="text" name="username" /></p>      <!-- Enter Teacher Username-->
          <p>New Password</p><p><input type="password" name="newpassword" /></p>  <!-- Enter Teacher Password--> 

Below is what the database table currently looks like:

TeacherUsername    TeacherPassword     TeacherSalt
j.lu               fgrfre4r4ffsdfv

So if j.lu wanted to change password, then she will enter in her username and then enter in a new password, then this should all be updated into the table above. But it isn’t updating anything.

Thank you

  • 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-09T06:18:06+00:00Added an answer on June 9, 2026 at 6:18 am

    You are fetching the username into variable named $username but you are binding a variable called $teacherusername in bind_param(), which is why the query does not fetch any results.

    The bind_param code should be:

        // You only need to call bind_param once
        $stmt->bind_param("s",$username);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a table in MySql using php. My code looks
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I'm using prepared statements and MySQLi, and am currently getting this error. PHP Catchable
I am trying to create a form that utilizes PHP and Jquery AJAX form
I'm using MySQL with php. Through a php script i'm trying to import a
I'm trying to connect to remote MySQL server with SSL from PHP using mysql_connect:
I am trying to connect to a MySQL server using PHP's 'mysql_connect()' function, but
i am trying to pass date to mysql query using php, but i am
I am trying to run a mysql insert query using php exec with parameters.
I'm using MySQLi with PHP(5.2.4) MySQL(5.0.51a) on Ubuntu 8.04 LAMP. The relevant Db tables

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.