<?php
$host = 'localhost';
$user = 'ahmeuesz_dino';
$pwd = 'X39IW2ho3^5h6d_5';
$dbname = 'ahmeuesz_myapp';

$conn = mysqli_connect($host, $user, $pwd, $dbname);

if (!$conn) {
    echo "Connection failed: " ;
}


if (isset($_POST['login'])) {
    $email = $_POST['email'];
    $password = $_POST['password'];

    $query = "SELECT * FROM login WHERE email='$email' AND password='$password'";
    $result = mysqli_query($conn, $query);

    if (mysqli_num_rows($result) == 1) {
        header('Location:home.php');
        exit();
    } else {
        $error = "Invalid Email or Password!";
    }
}

mysqli_close($conn);
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Login</title>
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="youtube.css">
</head>
<body>

  <div class="container">
    <form method="POST" class="login-box">
      <h2>Welcome Back 👋</h2>
      <div class="input-group">
        <input type="email" name="email" placeholder="Enter your email" required>
      </div>
      <div class="input-group">
        <input type="password" name="password" placeholder="Enter your password" required>
      </div>
      <button type="submit" name="login" class="btn">Login</button>
      <?php if ($error): ?>
        <p class="error-msg"><?= $error ?></p>
      <?php endif; ?>
    </form>
  </div>

  <section class="demo-section">
    <h2>💻 DEMO CODE</h2>
    <p>Click below to view the PHP code used for this login system.</p>
    <a href="showcode.php?file=login.php" class="btn">Show Code</a>
  </section>

  <?php include 'youtube.php'; ?> 

</body>
</html>
