<?php
session_start();
include 'admin/includes/database.php';
include 'admin/includes/functions.php';
$conn= new Functions();

if(!empty($_POST['name']) && !empty($_POST['email'])
    && !empty($_POST['subject'])){
    $name = $_POST['name'];
    $email= $_POST['email'];
    $subject = $_POST['subject'];
    $message= $_POST['message'];
    $phone= $_POST['phone'];


    //process  updating  of data into database

    $sql = "INSERT INTO `contact-messages` (name, email, phone, subject, message) 
              VALUES(:name, :email, :phone, :subject, :message)";
    $conn->query($sql);
    $conn->bind(":name", $name);
    $conn->bind(":email", $email);
    $conn->bind(":phone", $phone);
    $conn->bind(":subject", $subject);
    $conn->bind(":message", $message);

    $send = $conn->execute();
    if ($send) {
        echo "<p class='alert alert-success alert-dismissible fade show' role='alert'>
                    <i class='fas fa-check-circle'></i> Your message was sent successfully.
                  <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\">
                             <span aria-hidden=\"true\">×</span>
                  </button>
                  <meta http-equiv='refresh' content='3; index'>
           </p>";
    } else {
        echo "<p class='alert alert-danger alert-dismissible fade show' role='alert'>
                    <i class='fas fa-ban'></i> An error occurred while sending message.
                  <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\">
                             <span aria-hidden=\"true\">×</span>
                  </button>
                  <meta http-equiv='refresh' content='4; index'>
           </p>";
    }




}else{
    echo "<p class='alert alert-danger alert-dismissible fade show text-center' role='alert'>
              <i class='fas fa-ban'></i>
               Fields marked (*) are required.
                  <button type='button' class='close' data-dismiss='alert' aria-label='Close'>
                             <span aria-hidden='true'>×</span>
                  </button>
           </p>";
}




