Jump to content

Broken change password script


navybofus

Recommended Posts

changepass.php

include 'db.php';
$id = $_GET['id'];
$new_password = $_POST['new_password'];
$old_password = $_POST['old_password'];
$old_password = md5($old_password);
$new_password = md5($new_password);
$sql = mysql_query("SELECT * FROM users WHERE password='$old_password' AND userid='$id'");
$change_check = mysql_num_rows($sql);

if ($change_check > 0) {
     mysql_query("UPDATE users SET password='$new_password' WHERE userid='$id'");
        echo "Your password has been changed!";   
        header ("Location: login_success.php?id=$id");
                         } else {
        echo "Your old password password was not correct please try agian.;
              include 'login_success.php';
}

 

I realize that this probably isn't the best way to go about changing a password for an account but I am mostly just experimenting. I want to actually learn PHP instead of just copy + paste this and that. So I made my own script and I am getting an Unexpected $end. It identifies the last line of the script which is the closing php tag ?>

I think it has something to do with my IF Statement so I'll be looking it over but if anyone catches a bug please let me know. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/201039-broken-change-password-script/
Share on other sites

This is the corrected code.

Copy/pasted and it will work perfectly

 

include 'db.php';
$id = $_GET['id'];
$new_password = $_POST['new_password'];
$old_password = $_POST['old_password'];
$old_password = md5($old_password);
$new_password = md5($new_password);
$sql = mysql_query("SELECT * FROM users WHERE password='$old_password' AND userid='$id'");
$change_check = mysql_num_rows($sql);

if ($change_check > 0) {
     mysql_query("UPDATE users SET password='$new_password' WHERE userid='$id'");
        echo "Your password has been changed!";   
        header ("Location: login_success.php?id=$id");
                         } else {
        echo "Your old password password was not correct please try agian.";
              include 'login_success.php';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.