Jump to content

PHP update password


Glenskie
Go to solution Solved by Ch0cu3r,

Recommended Posts

For some reason I can get it to find the data and check if you submitted the correct old password but it will not update the new one? I'm not sure what to do next I have tried everything...

<?php
include 'header.php';
if (isset ($_POST['passupdate'])){
$pass = $_POST['pass'];


$opass = $_POST['opass'];


$db_passwordcheck = md5($opass);


$db_password = md5($salt.$pass);


$sql = mysql_query("SELECT * FROM members WHERE username='$username' AND password='$db_passwordcheck'"); 
$login_check = mysql_num_rows($sql);


if($login_check > 0){ 
     
$updatepass = "UPDATE members SET password='$db_password' WHERE username=$username";
$result = mysql_query($updatepass);
$congrats = "password updated.";


}else{


$congrats = "wrong password try again...";
}
}


?>
<form class="form-1" method="POST">


<label for="opassword">Old Password: </label>
<input id="opass" type="password" name="opass" placeholder="old password" />


<label for="password">New Password: </label>
<input id="pass" type="password" name="pass" placeholder="new password" />


<input type="submit" id="passupdate" name="passupdate" value="Update Password" class="btn right" />
<?php print($congrats);?>
</form>
Link to comment
Share on other sites

  • Solution

$username in the update query should be wrapped in quotes

$updatepass = "UPDATE members SET password='$db_password' WHERE username='$username'";

If the password is still not updating you'll want to check to see to see if mysql_query is failing due to an error, then use mysql_error to find out what the error is.

Edited by Ch0cu3r
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.