mysql - PHP Insertion issue with 'id'
问题描述
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.
解决方案
推荐阅读
- android - Android:从 API 29 中的现有 URI 覆盖文件
- vue.js - 父子之间的双向数据绑定
- .htaccess - htaccess 用不同的文件访问重写 url 路径
- python - 划分列表元素并将它们附加到新列表
- appium - WebDriverAgent 文件夹缺少 appium 1.15.1
- amazon-web-services - AWS Lambda 函数:它不显示现有角色的列表
- mysql - 查看 Libreoffice Base 对 mysql 的查询
- python - 如何使用 Django Filters 过滤同一字段的多个值?
- python - 从 Python 中的父文件夹导入模块
- c# - 无法使用 SharePoint 客户端 API 列出文件/文件夹