<?php
  session_start();
include_once('../../../admin/db/saucerer.php');

  if(isset($_POST['submit'])){



            if($_POST['username'] != ''){

                $_SESSION['username'] = $_POST['username'];

            }

            else {

  $sql = "SELECT * FROM xmas_party WHERE email = '".$_POST['email']."'";
            $query = $conn->query($sql);
            if($query->num_rows > 0){

                $_SESSION['error'] = "<span style='color:#A87E2C;font-size: 14px;'>Sorry, the Cornerstone Christmas Party is past due which was set on 14th December 2025!</span>";

                //return the inputted fields
                $_SESSION['email'] = $_POST['email'];

            }

            else {

    $event_id = $_POST['event_id'];
    $event = $_POST['event'];
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = addslashes($_POST['email']);
    $child_no = $_POST['child_no'];
    $suggestion = $_POST['suggestion'];


    mysqli_query($conn,"insert into `xmas_party` (`event_id`, `event`, `name`, `phone`, `email`, `child_no`, `suggestion`, `seen`) values ('$event_id', '$event', '$name', '$phone', '$email', '$child_no', '$suggestion', 'Late')") or die(mysqli_error());

    //use for MySQLi OOP
    if($conn){
      $_SESSION['success'] = "<span style='color:#A87E2C; font-weight:bold; font-size: 12px;'>Sorry, the Cornerstone Christmas Party is past due which was set on 14th December 2025!</span>";
    }
    
    
    else{
      $_SESSION['error'] = "<span style='color:#A87E2C; font-weight:bold; font-size: 12px;'>Sorry, the Cornerstone Christmas Party is past due which was set on 14th December 2025!</span>";
    }
  }

 }

}

header('location: ../');

?>