<?php
session_start();

if (empty($_SESSION['signup_email'])) {
    header("Location: SS_Signup_pg2.php");
    exit();
}

$error = "";

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $Q1 = trim($_POST['Q1']);
    $Q2 = trim($_POST['Q2']);
    $Q3 = trim($_POST['Q3']);
    $Q4 = trim($_POST['Q4']);

    if (!$Q1 || !$Q2 || !$Q3 || !$Q4) {
        $error = "Please answer all 4 questions.";
    } else {
        $_SESSION['signup_Q1'] = $Q1;
        $_SESSION['signup_Q2'] = $Q2;
        $_SESSION['signup_Q3'] = $Q3;
        $_SESSION['signup_Q4'] = $Q4;

        header("Location: SS_Signup_pg4.php");
        exit();
    }
}
?>
<!DOCTYPE html>
<html>
  <head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Sign Up - Smart Spender</title>
  <link rel="stylesheet" href="styles.css">
</head>

<body>
  <!-- Logo top-left -->
  <header class="signup-header">
  <div class="brand">
  <span class="logo">&#128178;</span>
  <span class="name"><strong>Smart</strong> <br> 
  <strong>Spender</strong> </span>
    </div>
  </header>
<?php if ($error) echo "<p style='color:red'>$error</p>"; ?>

  <!-- Main content -->
  <main class="signup-main container">
    <h1>Please complete security questions</h1>

<form class="signup-form" action="SS_Signup_pg3.php" method="post">
    <label>Oldest Sibling’s Middle Name:
        <input class="signup-form" name="Q1" required>
    </label><br>

    <label>City Born:
        <input class="signup-form"  name="Q2" required>
    </label><br>

    <label>Dream Job:
        <input class="signup-form" name="Q3" required>
    </label><br>

    <label>First Job Title:
        <input class="signup-form" name="Q4" required>
    </label><br>

    <button class="btn" type="submit">Next</button>
</form>

</body>
</html>
