Mehtabyte Posted August 8, 2009 Share Posted August 8, 2009 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. Quote Link to comment Share on other sites More sharing options...
abazoskib Posted August 8, 2009 Share Posted August 8, 2009 try this: mysql_query("UPDATE users SET password='$newpw' WHERE username='$username'"); Quote Link to comment Share on other sites More sharing options...
Mehtabyte Posted August 10, 2009 Author Share Posted August 10, 2009 Oh, of course! Silly error by me, thanks ever so much for helping me get that done. Good work! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.