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

  • Home
  • SEARCH
  • 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 9226015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:43:31+00:00 2026-06-18T04:43:31+00:00

im writing this php script to update user passwords, requiring old pasword, new and

  • 0

im writing this php script to update user passwords, requiring old pasword, new and new confirmation. It all works it seems up to the actual UPDATE mysql statement. Not sure what I’ve done wrong, al help appreciated!

Also, I am aware its not secure and such, I am just trying ot make it work first im a php newbie!

I’m tearing my hair out, when I run this, everything seems to work except it breaks just before if (empty($error)){ , i have tested the echo for session email and it displays that, however it does not update the database with the new password. Please help! below is my code:

<?php
session_start();

include('database_connection.php');

$error = array();

if (empty($_POST['oldpassword'])){
$error[] ='You did not enter your current password!';
} else {
    $oldpassword = $_POST['oldpassword'];
}



if (empty($_POST['newpassword'])){

    $error[] = 'You did not enter a new password!';
} else {
    if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["newpassword"])){
        $newpassword = $_POST['newpassword'];
    } else{
        $error[] = 'Password must be at least 8 characters and must contain at least one lower case letter, one upper case letter and one digit!';
    }
}

if (empty($_POST['newpasswordcon'])){
    $error[] = 'You did not enter your new password confirmation!';
} else {
    if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["newpasswordcon"])){
        $newpasswordcon = $_POST['newpasswordcon'];
    } else{
        $error[] = 'Password must be at least 8 characters and must contain at least one lower case letter, one upper case letter and one digit!';
    }
}


if($_POST['newpassword'] != $_POST['newpasswordcon']){
$error[] ='New password and confirmation do not match!' ;
}


$sql = "SELECT password FROM users WHERE email='" . $_SESSION['email'] . "'";
$result = mysql_query($sql);


if( $r = mysql_fetch_array($result) ) {
extract($r);



if($_POST['oldpassword'] != $password);{
$error[] ='Incorrect current password!';

}

//breaks here
echo $_SESSION['email'];

if (empty($error)){

echo $_SESSION['email'];
mysql_query("UPDATE users SET password='$newpassword' WHERE email='" . $_SESSION['email'] . "'");


echo '<p class ="alert alert-success fade in">Success! Your password has been updated!</p>';

}
} else{

    foreach ($error as $key => $values) {

            echo '<p class ="alert alert-error fade in">'.$values.'</p>';


}
}
?>
  • 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-18T04:43:33+00:00Added an answer on June 18, 2026 at 4:43 am

    There is a semicolon which should not be there.

    if ($_POST['oldpassword'] != $password);{ // <- remove this semicolon after )
       $error[] ='Incorrect current password!';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a php script to compare the similarity of 2 strings. This works
I am writing a simple script php. This script has to know if a
I am writing temporary PHP script to update MySQL database of my vBulletin forum.
I'm writing a script in PHP to allow a user to change their password.
I'm having some difficulty writing this code in php. I want to create a
I have this code in PHP writing views to a text-file and just increasing
Often when writing PHP I'll have it output some HTML like this - echo
I'm writing bug tracking software in PHP, and today I saw this in another
This is my first question :). Im writing a little twitter app in PHP
I'm writing a PHP script that autoconfigures a device over Telnet, and I need

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.