警告:mysqli_fetch_array()要求参数1为mysqli_result,布尔值在第14行的D:\ xampp \ htdocs \ wordpress \ wp-content \ themes \ twentyseventeen \ booking.php中给出。
显示上述错误?
第14行是:if ($qur) {
include_once('config.php');
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$username = isset($_POST['username']) ? mysqli_real_escape_string($conn,
$_POST['username']) : "";
$service = isset($_POST['service']) ? mysqli_real_escape_string($conn,
$_POST['service']) : "";
$employee = isset($_POST['employee']) ? mysqli_real_escape_string($conn,
$_POST['employee']) : "";
$date = isset($_POST['date']) ? mysqli_real_escape_string($conn,
$_POST['date']) : "";
$booking_time = isset($_POST['booking_time']) ?
mysqli_real_escape_string($conn, $_POST['booking_time']) : "";
$duration = isset($_POST['duration']) ? mysqli_real_escape_string($conn, $_POST['duration']) : "";
$sql = "INSERT INTO `booking_api` (`id`,`username`, `service`, `employee`, `date`,`booking_time`, `duration`) VALUES (NULL,'$username', '$service','$employee', '$date', '$booking_time','$duration');";
echo $sql;
$qur = mysqli_query($conn, $sql);
if ($qur) {
$fetch = mysqli_fetch_array($qur);
if (strlen($fetch["id"]) > 0) {
// base64 encodes the header json
$encoded_header = base64_encode('{"alg": "HS256","typ": "JWT"}');
// base64 encodes the payload json
$encoded_payload = base64_encode('{"first_name":'.$fetch["first_name"].' "last_name": '.$fetch["last_name"].' "username": '.$fetch["username"]
.' "email":'.$fetch["email"].' "password":'.$fetch["password"].' "phone_number":'.$fetch["phone_number"].'}');
// base64 strings are concatenated to one that looks like this
$header_payload = $encoded_header . '.' . $encoded_payload;
//Setting the secret key
$secret_key = 'Octaviasecretkey';
// Creating the signature, a hash with the s256 algorithm and the secret key. The signature is also base64 encoded.
$signature = base64_encode(hash_hmac('sha256', $header_payload, $secret_key, true));
// Creating the JWT token by concatenating the signature with the header and payload, that looks like this:
$jwt_token = $header_payload . '.' . $signature;
//listing the resulted JWT
//echo $jwt_token;
$json = array("status" => 1, "msg" => "Congratulations, Booking
Confirmed!");
} else {
$json = array("status" => 0, "msg" => "Error! Booking");
}
} else {
$json = array("status" => 0, "msg" => "Request method not accepted");
}
}
/* Output header */
header('Content-type: application/json');
echo json_encode($json);
Booking.php sql文件
CREATE TABLE `booking_api` (
`id` int(150) NOT NULL,
`username` varchar(300) NOT NULL,
`service` varchar(200) NOT NULL,
`employee` varchar(200) NOT NULL,
`date` varchar(150) NOT NULL,
`booking_time` varchar(150) NOT NULL,
`duration` varchar(150) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `booking_api`
--
INSERT INTO `booking_api` (`id`, `username`, `service`, `employee`,
`date`, `booking_time`, `duration`) VALUES
(1, 'jack@gmail.com', 'Scalp Massage', 'Massage Employee 1', '2/02/2018',
'11:04 Am', '50 mins'),
(2, 'amrish@gmail.com', 'Personalized Massage', 'Massage Specialist',
'2/02/18', '11:27 AM', '50 mins'),
(3, 'jack@gmail.com', 'Deep Tissue Massage', 'Massage Employee 5',
'2/02/2018', '6:16 PM', '50 mins'),
(4, 'disha@gmail.com', 'Swedish Massage', 'Massage Employee 1',
'2/02/2018', '6:25 PM', '45 mins'),
(5, 'jack@gmail.com', 'Swedish Massage', 'Massage Employee 7',
'5/02/2018', '10:46 AM', '60 mins'),
(6, 'test@gmail.com', 'Scalp Massage', 'Massage Employee 4', '6/02/2018',
'1:50 PM', '45 mins'),
(7, 'test@mail.com', 'Head Massage', 'Massage Employee ', '26/02/2018',
'1:50 PM', '45 mins'),
(8, 'test@mail.com', 'Head Massage', 'Massage Employee ', '26/02/2018',
'1:50 PM', '45 mins'),
(9, 'test@mail.com', 'Head Massage', 'Massage Employee ', '26/02/2018',
'1:50 PM', '45 mins'),
(10, 'test@mail.com', 'Head Massage', 'Massage Employee ', '26/02/2018',
'1:50 PM', '45 mins'),
(11, 'test@mail.com', 'Head Massage', 'Massage Employee ', '26/02/2018',
'1:50 PM', '45 mins'),
(12, 'test@mail.com', 'Head Massage', 'Massage Employee ', '26/02/2018',
'1:50 PM', '45 mins'),
(13, 'test@mail.com', 'Personalised Massage', 'Massage Employee ',
'28/02/2018', '11:24 PM', '45 mins'),
(14, '', '', '', '', '', ''),
(15, '', '', '', '', '', ''),
(16, 'test@mail.com', 'Personalised Massage', 'Massage Employee ',
'28/02/2018', '11:24 PM', '45 mins');
答案 0 :(得分:0)
听起来你希望它为每条记录生成一个新的ID,最好使用auto_increment键。这意味着您的表定义是......
CREATE TABLE `booking_api` (
`id` int(150) NOT NULL AUTO_INCREMENT,
`username` varchar(300) NOT NULL,
`service` varchar(200) NOT NULL,
`employee` varchar(200) NOT NULL,
`date` varchar(150) NOT NULL,
`booking_time` varchar(150) NOT NULL,
`duration` varchar(150),
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
然后你插入会变成......
$sql = "INSERT INTO `booking_api` (`username`, `service`, `employee`, `date`,`booking_time`, `duration`)
VALUES ('$username', '$service','$employee', '$date', '$booking_time','$duration');";
echo $sql;
$qur = mysqli_query($conn, $sql);
if ($qur) {
// Fetch id
$id = mysqli_insert_id($conn);
mysqli_insert_id()
获取为连接上的最后一个INSERT生成的新ID。