I'm trying to resolve an issue with an app. Originally we had problems due to PHP upgrading from PHP5 to PHP7. This seems to have been corrected in places, but now I am having problems again.
Can someone please check the syntax to check if it is inputting right?
if($_POST['create_special_appointment']){
$customer_id = htmlspecialchars($_POST['customer'], ENT_QUOTES);
$category_id = htmlspecialchars($_POST['category'], ENT_QUOTES);
$start_date = htmlspecialchars($_POST['start_date'], ENT_QUOTES);
$end_date = htmlspecialchars($_POST['end_date'], ENT_QUOTES);
$start_time = htmlspecialchars($_POST['start_time'], ENT_QUOTES);
$end_time = htmlspecialchars($_POST['end_time'], ENT_QUOTES);
$booked_for = post_array_to_explode($_POST['booked_for']);
$notes = htmlspecialchars($_POST['notes'], ENT_QUOTES);
$session_id = htmlspecialchars($_POST['session_id'], ENT_QUOTES);
$time = date("Y-m-d H:i:s");
$agent_id = get_agent_from_session($session_id, 'id');
//if(!($start_time)){$start_time = '00:00';}
//if(!($end_time)){$end_time = '00:00';}
//$start_date = $start_date.' '.$start_time;
//$end_date = $end_date.' '.$end_time;
$date=date('Y-m-d',strtotime($date));
$start_date = $start_date.' '.$start_time.":00";
$end_date = $end_date.' '.$end_time.":00";
//$start_date = format_datetime_mysql($start_date);
//$end_date = format_datetime_mysql($end_date);
$insert = $dbh->exec("INSERT INTO calendar_special(start_date, end_date, notes, category_special_id, added_by, booked_for, date_added, customer_id) VALUES ('$start_date', '$end_date', '$notes', '$category_id', '$agent_id', '$booked_for', '$time', '$customer_id')");
if($insert){
$notification_msg[] = array(type=>'alert-success', h4=>'Success!', msg=>'Appointment Created');
header('Location: ' . $_SERVER['HTTP_REFERER']);
}else{
$notification_msg[] = array(type=>'alert-warning', h4=>'Warning!', msg=>'Appointment NOT Created');
mysqli_error($con);
var_dump($_REQUEST);
print_r($dbh->errorInfo());
}
//temp-code
//var_dump($insert);
}
Actual form code is:
<select name="customer" id="customer-single" style="width:100%">
<option value="">Select a customer (Optional)</option>
<?php foreach(customer_array($ajax['0']) as $customer){ ?>
<option value="<?php echo $customer['id'] ?>">
<?php echo $customer['business_name'] ?> - <?php echo $customer['first_name'] ?> <?php echo $customer['last_name'] ?></option>
<?php } ?>
</select>
And the error I'm getting is:
"Warning! Appointment NOT Created"
array(11) { ["session_id"]=> string(64) "c5ec66786328e97af8f8fb6771912b58c5869986816b3d2bc9916b7e740cff44" ["create_special_appointment"]=> string(4) "true" ["customer"]=> string(0) "" ["category"]=> string(1) "1" ["start_date"]=> string(10) "2018-10-23" ["start_time"]=> string(5) "10:35" ["end_date"]=> string(10) "2018-10-31" ["end_time"]=> string(5) "10:35" ["booked_by"]=> string(1) "5" ["booked_for"]=> array(1) { [0]=> string(2) "71" } ["notes"]=> string(18) " Paul Holiday Test" } Array ( [0] => 22007 [1] => 1366 [2] => Incorrect integer value: '' for column 'customer_id' at row 1 )
Apologies if this question has been worded incorrectly, and if so, please advise.