<?php
session_start();
<?php
$host = "localhost";
$user = "odmr9632_userdb";
$pass = "@Sukabumi2018";
$db   = "odmr9632_order_db";

$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
  die("Koneksi gagal: " . $conn->connect_error);
}
?>

if ($conn->connect_error) {
  die("Koneksi gagal: " . $conn->connect_error);
}

$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $username = trim($_POST['username']);
  $password = trim($_POST['password']);

  // Ambil dari tabel warehouse_admin
  $stmt = $conn->prepare("SELECT * FROM warehouse_admin WHERE username=? AND password=?");
  $stmt->bind_param("ss", $username, $password);
  $stmt->execute();
  $result = $stmt->get_result();

  if ($result->num_rows > 0) {
    $_SESSION['warehouse'] = $username;
    header("Location: dashboard_warehouse.php");
    exit;
  } else {
    $error = "❌ Username atau Password salah.";
  }
}
?>

<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <title>Login Warehouse</title>
  <style>
    body { font-family: Arial; background: #f2f2f2; padding: 50px; }
    .box { max-width: 400px; margin: auto; background: white; padding: 30px; border-radius: 10px; box-shadow: 0 0 10px #ccc; }
    h2 { text-align: center; color: #e53935; }
    label { display: block; margin-top: 15px; }
    input[type="text"], input[type="password"] {
      width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px;
    }
    .btn { margin-top: 20px; background: #e53935; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; width: 100%; }
    .msg { color: red; text-align: center; margin-top: 15px; }
  </style>
</head>
<body>
<div class="box">
  <h2>🔐 Login Warehouse</h2>
  <?php if ($error): ?><div class="msg"><?= $error ?></div><?php endif; ?>
  <form method="post">
    <label>Username</label>
    <input type="text" name="username" required>

    <label>Password</label>
    <input type="password" name="password" required>

    <button type="submit" class="btn">Login</button>
  </form>
</div>
</body>
</html>
