<?php
session_start(); // Start the session to store the user ID

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  // Get the form data
  $email = $_POST['email'];
  $password = $_POST['password'];

  // Validate the form data
  if (empty($email) || empty($password)) {
    echo 'Please enter your email and password';
  } else {
    // Check the user's credentials against the database
    $conn = mysqli_connect('localhost', 'root', '', 'token');
    $sql = "SELECT id FROM users WHERE email = '$email' AND password = '$password'";
    $result = mysqli_query($conn, $sql);

    if (mysqli_num_rows($result) == 1) {
      // Store the user ID in a session variable and redirect to the dashboard
      $row = mysqli_fetch_assoc($result);
      $_SESSION['user_id'] = $row['id'];
      header("Location: welcome/index.php?id=" . $row["id"]);
      exit();
    } else {
      echo 'Incorrect email or password';
    }

    mysqli_close($conn);
  }
}
?>
