My update queries won't work

James

I've got a basic registration, login, profile page webpage up and running and have recently begun implementing forgot password functionality.

Everything seems to be running, but my update queries just don't seem to fire.

For example, the code on my forgot password page creates a new reset key if the email address and things match and then emails the code inside a link (i.e www.mydomain.net/forgotpassword.php?key=xxx).

The page tests if a key is present when you land, the code of which is below:

include ('database_connection.php');
session_start();
if($_GET['key'])
{
    $key = $_GET['key'];
     $query_check_key = "SELECT * FROM password_reset WHERE Reset_link='$key' AND Expiration>=NOW() AND used=0";
     $result_check_key = mysqli_query($dbc, $query_check_key);
     $result_check_row = $result_check_key->fetch_array(MYSQLI_ASSOC);
     if(!$result_check_key) {
        echo "Error";
     }

      if (mysqli_num_rows($result_check_key) == 1)
      {
         // Update the database to set the "used" field to 1
        $query_link_used = "UPDATE password_reset SET Used=1 WHERE Reset_link='$key'";
        $result_link_used = mysqli_query($dbc, $query_activate_account) ;

        $_SESSION['Memberid'] = $result_check_row['Memberid']; 
        header("Location: reset_password.php");
      }
}

The if statement evaluates to true when I try this as the page is redirected to reset_password.php and the session is successfully created correctly. But when I check the database table the Used field has not been updated.

Similarly on the reset_password.php page the update query won't work either:

if (empty($error))
        {
            //Query to change password
            $query_change_password = "UPDATE members SET Password=$hashed_password WHERE Memberid=$Memberid";
            $result_change_password = mysqli_query($dbc, $query_change_password);

            if (mysqli_affected_rows($dbc) > 0)//if update query was successful
            {
                echo '<div class="success">Your password has now been reset. You may now <a href="login.php">Log in</a></div>';

            } else
            {
                echo '<div class="errormsgbox">Oops !Your password could not be reset. Please contact the system administrator.</div>';
            } 
            mysqli_close($dbc);
        }

The error array is definitely empty and the if statement checking the affected rows remains at 0 as that statement returns false and falls back to the else statement.

I've run the queries in PHPMyAdmin and they work fine so I cannot see what the issue is. Any help is greatly appreciated.

Al Amin Chayan

start session in your reset_password.php page and update query string:

session_start();
if (empty($error))
{
    $Memberid = $_SESSION['Memberid'];
    //Query to change password
    $query_change_password = "UPDATE members SET Password='$hashed_password' WHERE Memberid='$Memberid'";

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

The hover for my buttons and links won’t work

분류에서Dev

PDO won't update my data in the database, why?

분류에서Dev

Lightbox won't work when my site css page is linked

분류에서Dev

RequestContext won't work

분류에서Dev

AJAXify won't work on phpBB?

분류에서Dev

Program won't work in FireFox

분류에서Dev

Fade in Function Won't Work

분류에서Dev

Getting message on AVD "This app won't work unless you update Google play services"

분류에서Dev

Additionally filter buttons won´t update the URL hash (see my JSFIDDLE)

분류에서Dev

My ListView won't work ...it says: "Unfortunately your app has stopped"

분류에서Dev

Mint 19 - rkhunter 1.4.6 won't update

분류에서Dev

CloudKit-Won't update (Swift)

분류에서Dev

Why won't this regexp in htaccess work properly?

분류에서Dev

Alsamixer won't work with bluetooth device

분류에서Dev

Post variables with ajax won't work

분류에서Dev

Simple class won't work in C++

분류에서Dev

Laravel named routes won't work on wampserver

분류에서Dev

Why won't the routing work in this code?

분류에서Dev

Now visudo won't work at all

분류에서Dev

Why won't this MySQL stored procedure work?

분류에서Dev

For /F "skip=0" won't work as expected

분류에서Dev

I'm trying to get jquery working in the background.js of my chrome extension and it won't work. why?

분류에서Dev

Why won't jQuery remove my class?

분류에서Dev

PhpStorm won't recognize the methods of my object

분류에서Dev

Javascript won't run on my HTML page

분류에서Dev

Java won't read my second process

분류에서Dev

Windows 7 computer won't boot and recovery doesn't work

분류에서Dev

Ubuntu 14.04 won't go past the log in screen; update

분류에서Dev

Google Chrome update won't install due to unmet dependencies

Related 관련 기사

뜨겁다태그

보관