<?php
require('config.php'); 
$service = $_POST['service']; 
//echo $service;
$email_header = $_POST['email_header']; 
$email_description = $_POST['email_description']; 
$email_form = $_POST['email_form']; 
$email_form_description = $_POST['email_form_description']; 
$email_form_name = $_POST['email_form_name']; 
$email_form2 = $_POST['email_form2']; 
$email_form2_description = $_POST['email_form2_description']; 
$email_form2_name = $_POST['email_form2_name']; 
$email_form3 = $_POST['email_form3']; 
$email_form3_description = $_POST['email_form3_description'];
$email_form3_name = $_POST['email_form3_name']; 
$reminderonoff = $_POST['reminder_on_off']; 

$linkID = new PDO('mysql:host='.Config::DB_HOST.';dbname='.Config::DB_NAME, Config::DB_USERNAME, Config::DB_PASSWORD);
$linkID->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Setting ERRMODE
$data = [
    'service' => $service,
    'email_header' => $email_header,
    'email_description' => $email_description,
    'email_form' => $email_form, 
    'email_form_description'=> $email_form_description, 
    'email_form_name'=>$email_form_name, 
    'email_form2' => $email_form2, 
    'email_form2_description'=>$email_form2_description, 
    'email_form2_name'=>$email_form2_name, 
    'email_form3' => $email_form3,
    'email_form3_description' => $email_form3_description,
    'email_form3_name'=>$email_form3_name,
    'send_reminder'=>$reminderonoff, 

];

$result = $linkID->query("SELECT * FROM millie_service WHERE service='".$service."'")->fetchAll(PDO::FETCH_ASSOC);
//echo $result[0]['service']; 

if($result[0]['service'] == null){
   // echo 'here'; 
$sql = "INSERT INTO `millie_service`(`service`, `email_header`, `email_description`, `email_form`, `email_form_description`, `email_form_name`, `email_form_two`, `email_form_two_description`, `email_form_two_name`, `email_form_three`, `email_form_three_description`, `email_form_three_name`, `send_reminder`) VALUES (:service, :email_header, :email_description, :email_form, :email_form_description, :email_form_name, :email_form2, :email_form2_description, :email_form2_name, :email_form3, :email_form3_description, :email_form3_name, :send_reminder)"; 

}else{
    //echo 'here2';
$sql = "UPDATE millie_service SET service=:service, email_header=:email_header, email_description=:email_description, email_form=:email_form, email_form_description=:email_form_description, email_form_name=:email_form_name, email_form_two=:email_form2, email_form_two_description=:email_form2_description, email_form_two_name=:email_form2_name, email_form_three=:email_form3, email_form_three_description=:email_form3_description, email_form_three_name=:email_form3_name, send_reminder=:send_reminder WHERE service=:service"; 
}
$stmt= $linkID->prepare($sql);
$stmt->execute($data);
//echo $stmt; 

echo 'Success, return to mainpage!'


?>