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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:24:24+00:00 2026-06-03T05:24:24+00:00

I’m quite new with PHP/Jquery and I am trying to do an update password

  • 0

I’m quite new with PHP/Jquery and I am trying to do an update password script for my web site. So far the passwords update but I’m struggling to think of how I would validate this to check against the old password.

Also, how would it be possible to display the error messages in an alert box (like java alert window). The reason I ask is because I would need to create an alert box if the old password doesn’t match the password that exists in the database.

Any help on this would be much appreciated. If you need any additional code I will post this ASAP.

// *Update Profile Password* //
$("#btn-profile-update2").bind('click', function(){

       // Get info from text boxes
    /*    var profile_oldpassword = $('#txt-prof-oldp').val(); */
    var profile_newpassword = $('#txt-prof-newp').val();
    var profile_confirmpassword = $('#txt-prof-confp').val();

    new_password = $('#txt-prof-newp').val();
    old_password = $('#txt-prof-oldp').val();

    if (profile_newpassword !== profile_confirmpassword) {

        response = "Passwords entered do not match"

        alert(response);

        return;

   }

    // An array of field names to be updated
    var arr_field_names = Array();

    // Add the field name to index of array
    arr_field_names[0] = "Password";

    // An array of field values that correspond with our field names...
    var arr_field_values = Array();

    arr_field_values[0] = profile_newpassword;

    // Send to updateProfDetails function
    updatePassword(arr_field_names,arr_field_values,new_password,old_password);

    });

});

Which sends to this function:

function updatePassword(arr_field_names,arr_field_values,new_password,old_password) {

    // Ajax parameters...
    $.ajax({

        // Request sent from control panel, so send to cp.request.php (which is the handler)
        url: 'scripts/php/bootstrp/cp.request.php',
        type: 'GET',

        data: {

            ft: "password",
            table: "tblusers",
            oldpassword: old_password,
            newpassword: new_password,
            field_names: arr_field_names,
            field_values: arr_field_values,

            // Either pass a row id as the 'id' OR a where clause as the 'condition' never both
            id: null,
            condition: null
        },
        dataType: 'text',
        timeout: 20000,
        error: function(){
            $('#cp-div-error').html('');
            $('#cp-div-error').append('<p>There was an error updating the data, please try again later.</p>');
            $('#cp-div-error').dialog('open');
        },
        success: function(response){

            // Refresh page
           // location.reload(true);


        }
    });


}

and finally the PHP update:

public function password($tableName)
{

    $PDO = new SQL();
    $dbh = $PDO->connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);

    $username = UserAccount::get_useremail();
    $password = hash('sha256',trim($_GET['newpassword']));
    $oldpassword = hash('sha256',trim($_GET['oldpassword']));


        // Does the password given match the password held?
       $this->sql = "UPDATE $tableName SET password = '$password' WHERE UserName = '$username'";

    try {
                // Query
                $stmt = $dbh->prepare($this->sql);

                $stmt->execute();

                $count = $stmt->rowCount();

                echo $count.' row(s) updated by SQL: '.$stmt->queryString;

                $stmt->closeCursor();

            }

            catch (PDOException $pe) {
                echo 'Error: ' .$pe->getMessage(). 'SQL: '.$stmt->queryString;
                die();
            }

                // Close connection
                $dbh = null;

        }
  • 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-03T05:24:25+00:00Added an answer on June 3, 2026 at 5:24 am

    You almost got it.. key is here:

    success: function(response) { .. }
    

    just play with response maybe something like this:

    success: function(response) {
        if (response == "wrong password") alert ("don't guess");
        else if (response == "password changed") alert ('you got it! congrats!');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

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.