Login code

session_start();
if (isset($_SESSION['username'])) {
header('location: dashboard.php');
}

if(isset($_POST['submit'])){
  $username = mysqli_real_escape_string($conn, $_POST['username']);
  $password = mysqli_real_escape_string($conn, $_POST['password']);
  
  $query = mysqli_query($conn, "SELECT * FROM users WHERE username = '$username' AND password = '$password' ");
  $rows = mysqli_fetch_array($query);
  if($rows){
      $_SESSION['username'] = $rows['username'];
      header("location: dashboard.php");
  } else {
      $error = "Username Address and Password no match";
  }
  
}

Leave a comment