[Solved] my query doesn’t work [closed]


You need to use your condition inside the if($query), but i dont think is there any need to recheck because you are already checking in Query WHERE username = $username. So i have modified your code as:

Modified Code:

  $sql = "SELECT id, username, password FROM login WHERE username="$username" LIMIT 1";
  $query = mysqli_query($dbcon, $sql);
  if (!$query) {
    die(mysqli_error($dbcon));
  }
  else
  {
    $count = mysqli_num_rows($query); // check total no of rows

    if ($count > 0) 
    {
        session_start(); // start session
        $row = mysqli_fetch_row($query);
        $userId = $row[0]; // get userid from database
        $dbUsername = $row[1]; // get username from database
        $_SESSION['username'] = $dbUsername;
        $_SESSION['id'] = intval($userId);
        header('location: login.php');    
        die(); // using die() after header()
    }
    else{
        echo "incorrect username or password."; // if query not return anything print this.
    }  
  }

6

solved my query doesn’t work [closed]