Jump to content

[SOLVED] Change Password in MySQL - Written Script, mysteriously not working!


Mehtabyte

Recommended Posts

Hello. I am new to this forum, searched it, but haven't found any threads talking about changing passwords in MySQL.

 

You may be familiar with Eric 'phpFreak' Rosebrock's fantastic tutorial about how to create a Membership System, and it worked brilliantly for me - thanks Eric  ::)! It's at:

 

http://www.devarticles.com/c/a/PHP/Creating-a-Membership-System/

 

MySQL Server Version: 5.0.81-community

 

However, I have been trying to create a password change feature ever since, written a code which looks fine, but doesn't seem to work. Behold:

 

<?
session_start();
include 'db.php';
//define post variables
$username = $_POST['username'];
$password = $_POST['password'];
$newpw = $_POST['newpw'];

//stripslashes
$password = stripslashes($password);
$newpw = stripslashes($newpw);

// Convert password to md5 hash
$password = md5($password);
$newpw = md5($newpw);

// check if the user info validates the db
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
    while($row = mysql_fetch_array($sql)){
    foreach( $row AS $key => $val ){
        $$key = stripslashes( $val );
    }
mysql_query("UPDATE users SET password=$newpw WHERE username='$username'");
header ("Location: pwchanged.php");
exit();
}
}else{
header ("Location: successpwwrong.php");
exit();
}
?>

 

Here's my MySQL structure:

 

CREATE TABLE users (
  userid int(25) NOT NULL auto_increment,
  first_name varchar(25) NOT NULL default '',
  last_name varchar(25) NOT NULL default '',
  email_address varchar(25) NOT NULL default '',
  username varchar(25) NOT NULL default '',
  password varchar(255) NOT NULL default '',
  info text NOT NULL,
  user_level enum('0','1','2','3') NOT NULL default '0',
  signup_date datetime NOT NULL default '0000-00-00 00:00:00',
  last_login datetime NOT NULL default '0000-00-00 00:00:00',
  activated enum('0','1') NOT NULL default '0',
  PRIMARY KEY  (userid)
) TYPE=MyISAM COMMENT='Membership Information';

 

When I enter my old password, a new password and click "submit", the header is shown (pwchanged.php). However, the MySQL database isn't changed! Could anyone find out what's wrong? Thanks very much.

 

Have a nice day, I hope you can help me.

 

Mehtabyte.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.