title: How to update MySql column from -1 to 1 after login from PHP script
body: <p>Before I ask the question, I know there are issues with the SQL Injection, I am going to take care of it most likely with PDO, I am just trying to figure this out for now. </p>
  
  <p>I want PHP to read the status column from MySql and if the status column reads -1 where $username = ($_POST["username"])  I want PHP to initially send them to a "change password" screen and then after its changed send an update script to MySql to update column "status" from the default -1 to 1. </p>
  
  <p>If its 1 I want it to log in as normal and if its -1 I want them to be forced to change their password basically and I am having trouble locating a way to do this. </p>
  
  <p>Im assuming my update query would look something like this </p>
  
  <pre><code>$query = "UPDATE login SET status= 1 WHERE user_id='".$username ."' LIMIT 1";
  </code></pre>
  
  <p>My php login script so far</p>
  
  <pre><code>&lt;?php
  // Include config file
  require_once 'LoginConn.php';
  
  // Define variables and initialize with empty values
  $username = $password = "";
  $username_err = $password_err = "";
  
  // Processing form data when form is submitted
  if($_SERVER["REQUEST_METHOD"] == "POST"){
  
      // Check if username is empty
      if(empty(trim($_POST["username"]))){
          $username_err = 'Please enter username.';
      } else{
          $username = trim($_POST["username"]);
      }
  
      // Check if password is empty
      if(empty(trim($_POST['password']))){
          $password_err = 'Please enter your password.';
      } else{
          $password = trim($_POST['password']);
      }
  
      // Validate credentials
      if(empty($username_err) &amp;&amp; empty($password_err)){
          // Prepare a select statement
          $sql = "SELECT username, password FROM scorecardusers WHERE username = ?";
  
          if($stmt = mysqli_prepare($link, $sql)){
              // Bind variables to the prepared statement as parameters
              mysqli_stmt_bind_param($stmt, "s", $param_username);
  
              // Set parameters
              $param_username = $username;
  
              // Attempt to execute the prepared statement
              if(mysqli_stmt_execute($stmt)){
                  // Store result
                  mysqli_stmt_store_result($stmt);
  
                  // Check if username exists, if yes then verify password
                  if(mysqli_stmt_num_rows($stmt) == 1){                    
                      // Bind result variables
                      mysqli_stmt_bind_result($stmt, $username, $hashed_password);
                      if(mysqli_stmt_fetch($stmt)){
                          if(password_verify($password, $hashed_password)){
                              /* Password is correct, so start a new session and
                              save the username to the session */
  
  
                              session_start();
  
                              $value= $sql['password'];
  
  
                              $_SESSION['username'] = $username;      
                              header("location: Test.php");
                          } else{
                              // Display an error message if password is not valid
                              $password_err = 'The password you entered was not valid.';
                          }
                      }
                  } else{
                      // Display an error message if username doesn't exist
                      $username_err = 'No account found with that username.';
                  }
              } else{
  
                  echo "Oops! Something went wrong. Please try again later.";
              }
          }
  
          // Close statement
          mysqli_stmt_close($stmt);
      }
  
      // Close connection
      mysqli_close($link);
  }
  ?&gt;
  </code></pre>
  
  <p>UPDATED: I added this to my query and it updates correctly. </p>
  
  <pre><code>mysqli_query ($link, "UPDATE Users SET Status = '1' WHERE Status ='-1'and username ='".$username ."' LIMIT 1");
  </code></pre>
  
  <p>If anyone could help me understand how to pull the status area from my sql and redirect them to the change password page if the status =-1 that would be awesome.</p>
  
  <p>I am just trying to figure out how to redirect to change password if Status =-1 in mysql..</p>
  
  <p>SECOND UPDATE: Ive made a second query that checks the information and sends you to the change password log however I know this is not correct. I feel as if I am getting a lot closer to the answer though. The code works as far as getting me to the right screen but its not getting the correct information. I need the username to be a variable based on what the agent puts in. Again, any help here would be really appreciated. </p>
  
  <pre><code>        $id_get = "SELECT Status, username FROM scorecardusers WHERE Status = '-1' and username='MyName' LIMIT 1";
  
  
          if ($result=mysqli_query($link, $id_get))
          {   
  
        // Fetch one and one row// check if first time log in
    while ($row = mysqli_fetch_assoc($result))
      {
     $Status=$row["Status"];
     $username=$row["MyName"];
        if ($Status== "-1" &amp;&amp; $username =="MyName");
        var_dump($result);
          header("location: ChangePW.php");
  
      }
    // Free result set
    mysqli_free_result($result);
  }
  </code></pre>