<?php
if(session_status() == PHP_SESSION_NONE)
{
  session_start();
}
require_once('mysqli_con.php');
$emailPost = $_POST["email"];
$password = $_POST["pw"];
$sql = "SELECT * FROM buyer WHERE email = '$emailPost'";
$result = mysqli_query($conn, $sql);
$byrID = null;
if (mysqli_num_rows($result) >= 0) {
  // output data of each row
  while($row = mysqli_fetch_assoc($result)) {
    if($password == $row["password"]){
      $buyer_id = $row['buyer_id'];
      $item3 = $row["first_name"];
      $lastname = $row["last_name"];
      $fon = $row["phone"];
      $address = $row["address"];
      $resultImage = $row['image'];
      $eTest = $row['email'];
      $items_id = $row['items_id'];

      $_SESSION['buyer_id'] = $buyer_id;
      $byrID = $buyer_id;
      $_SESSION ['first_name'] = $item3;
      $_SESSION ['last_name'] = $lastname;
      $_SESSION ['phone'] = $fon;
      $_SESSION ['address'] = $address;
      $_SESSION ['image'] = $resultImage;
      $_SESSION ['email'] = $eTest;
      $_SESSION ['items_id'] = $items_id;
      $_SESSION ['loggedin'] = true;

      $ok = 1;
    }
    else{
      $ok = 0;
    }
  }
} else {
  echo "0 results";
  $ok = 0;
}
mysqli_close($conn);

if($ok > 0){
  $_SESSION['byrID'] = $byrID;
  echo "<script type='text/javascript'>
  window.location.replace('/fyp_draft/userP.php?byrID=".$byrID."');
  </script>";

  //header("Location: /fyp_draft/userP.php?byrID=".$byrID);
  //echo $item3;
  ?>
  <!--<meta http-equiv="refresh" content="0; URL='../fyp_draft/userP.php' =  " />-->
  <?php
}else{
  ?>
  <meta http-equiv="refresh" content="0;URL=../fyp_draft/login.php?hehe=<?php echo "t";?>" />

  <?php
}

?>
