【发布时间】:2020-02-18 10:59:28
【问题描述】:
我明白了
"您的 SQL 语法有错误;请查看手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 在第 1 行的 '1' 附近"
运行时的消息
private function saveBookingData(){
global $mysqli;
$sql = $mysqli->query("INSERT INTO bsi_bookings
(booking_id, booking_time, start_date, end_date, client_id,
total_cost, payment_amount, payment_type, special_requests)
values(".$this->bookingId.", NOW(),
'".$this->mysqlCheckInDate."',
'".$this->mysqlCheckOutDate."',
".$this->clientId.",
".$this->grandTotalAmount.",
".$this->totalPaymentAmount.",
'".$this->paymentGatewayCode."',
'".$this->clientdata['message']."')");
foreach($this->reservationdata as $revdata){
foreach($revdata['availablerooms'] as $rooms){
$sql = $mysqli->query("INSERT INTO bsi_reservation
(bookings_id, room_id, room_type_id)
values(".$this->bookingId.", ".$rooms['roomid'].",
".$revdata['roomtypeid'].")");
}
}
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$result = $mysqli->query($sql);
if (!$result) {
printf("%s\n", $mysqli->error);
exit();
}
}
其他信息
表一
CREATE TABLE `bsi_bookings` (
`booking_id` int(10) UNSIGNED NOT NULL,
`booking_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`start_date` date NOT NULL DEFAULT '0000-00-00',
`end_date` date NOT NULL DEFAULT '0000-00-00',
`client_id` int(10) UNSIGNED DEFAULT NULL,
`child_count` int(2) NOT NULL DEFAULT '0',
`extra_guest_count` int(2) NOT NULL DEFAULT '0',
`discount_coupon` varchar(50) DEFAULT NULL,
`total_cost` decimal(10,2) UNSIGNED NOT NULL DEFAULT '0.00',
`payment_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
`payment_type` varchar(255) NOT NULL,
`payment_success` tinyint(1) NOT NULL DEFAULT '0',
`payment_txnid` varchar(100) DEFAULT NULL,
`paypal_email` varchar(500) DEFAULT NULL,
`special_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
`special_requests` text,
`is_block` tinyint(4) NOT NULL DEFAULT '0',
`is_deleted` tinyint(4) NOT NULL DEFAULT '0',
`block_name` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
表 2
CREATE TABLE `bsi_reservation` (
`id` int(11) NOT NULL,
`bookings_id` int(11) NOT NULL,
`room_id` int(11) NOT NULL,
`room_type_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
【问题讨论】:
-
你能把
data types的database attributes发上来吗? -
@Robin Gillitzer 好的
-
你看我的回答了吗?我认为这是解决方案。
-
@rick 您的代码对 SQL 注入开放(或者假设实际上 checkInDate 或 checkOutDate 值可能来自用户输入。无论哪种方式,您都应该使用参数作为标准做法,以避免任何疑问)。
-
@rick 在bobby-tables.com/php 有一个关于 PDO(和其他库)的简单示例,bobby-tables.com 有一个卡通片,它简单而有趣地解释了 SQL 注入是如何发生的,以及风险是。对查询进行参数化是防止它的唯一可靠方法。