

<?php
include 'koneksi.php';

$username = mysqli_real_escape_string($koneksi, $_POST['username']);
$password = mysqli_real_escape_string($koneksi, $_POST['password']);

// Periksa apakah pengguna adalah pelanggan
$pelanggan_query = mysqli_query($koneksi, "SELECT * FROM tbl_pelanggan WHERE username='$username' AND password='$password'");
$pelanggan_data = mysqli_fetch_assoc($pelanggan_query);

// Periksa apakah pengguna adalah kurir
$kurir_query = mysqli_query($koneksi, "SELECT * FROM tbl_kurir WHERE username='$username' AND password='$password'");
$kurir_data = mysqli_fetch_assoc($kurir_query);

if ($pelanggan_data) {
    session_start();
    $_SESSION['id_pelanggan'] = $pelanggan_data['id_pelanggan'];
    $_SESSION['nama'] = $pelanggan_data['nama_pelanggan'];
    $_SESSION['username'] = $pelanggan_data['username'];
    $_SESSION['status'] = "pelanggan";

    header("location: home1.php");
} elseif ($kurir_data) {
    session_start();
    $_SESSION['id_kurir'] = $kurir_data['id_kurir'];
    $_SESSION['nama'] = $kurir_data['nama_kurir'];
    $_SESSION['username'] = $kurir_data['username'];
    $_SESSION['status'] = "kurir";

    header("location: home_kurir.php");
} else {
    // Jika login gagal
    header("location: login.php?alert=gagal");
}
?>
