<?php

require('config.php');

function randHash($len=32)
{
	return substr(md5(openssl_random_pseudo_bytes(20)),-$len);
}

$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


$company_name = $linkID->query("SELECT * FROM ea_settings WHERE ea_settings.id=14")->fetchAll(PDO::FETCH_ASSOC);
$company_email = $linkID->query("SELECT * FROM ea_settings WHERE ea_settings.id=15")->fetchAll(PDO::FETCH_ASSOC);
$company_link = $linkID->query("SELECT * FROM ea_settings WHERE ea_settings.id=16")->fetchAll(PDO::FETCH_ASSOC);

$waitlistfirstname = $_POST['waitlist-firstname']; 
$waitlistlastname = $_POST['waitlist-lastname']; 
$waitlistphonenumber = $_POST['waitlist-phonenumber']; 
$waitlistemail = $_POST['waitlist-email']; 
$waitlistnotes = $_POST['waitlist-notes']; 
$waitlistpharmacynotes = $_POST['waitlist-pharmacy-notes']; 
$waitlistservice = $_POST['waitlist-service']; 
$waitlisthash = $_POST['waitlisthash']; 
$waitlistid = $_POST['waitlistid'];
$waitlistbirthdate = $_POST['waitlist-birthdate'];

$servicewhich = $linkID->query("SELECT * FROM ea_services WHERE ea_services.id=".$waitlistservice)->fetchAll(PDO::FETCH_ASSOC);
//echo $servicewhich[0]['name'];
$data = [
    'firstname' => $waitlistfirstname,
    'lastname' => $waitlistlastname,
    'phonenumber' => $waitlistphonenumber,
    'email' => $waitlistemail,
    'birthdate' =>$waitlistbirthdate,
    'notes'=> $waitlistnotes, 
    'pharmacynotes' => $waitlistpharmacynotes, 
    'id'=>$waitlistid, 
    'service'=> $waitlistservice, 
    'hash'=> $waitlisthash,
];


$sql = "UPDATE waitlist SET firstname=:firstname, lastname=:lastname, phonenumber=:phonenumber, email=:email, birthdate=:birthdate, notes=:notes, pharmacynotes=:pharmacynotes, service=:service  WHERE hash=:hash AND id=:id";
//echo $sql; 
$stmt= $linkID->prepare($sql);
$stmt->execute($data);

 

echo 'Your record has been successfully edited. '




?>