อันนี้ โค้ด
<?php include("connect.php");?>
<?php
$sql="select * from book order by id desc LIMIT 1";
$result = $conn ->query($sql);
while ($rs = $result->fetch_object()){
//echo $rs->number
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Line Bot</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="md-12 mx-auto mt-5">
<h2>บันทึกสำเร็จ</h2>
</div>
</div>
<div class="container">
<a class="btn btn-primary" href="index.php">กลับสู่หน้าหลัก</a>
</div>
<?php
$text = "เลขทะเบียนส่ง : $rs->id
ที่ : $rs->number
ลงวันที่ : $rs->date
จาก : $rs->book_from
ถึง : $rs->book_to
เรื่อง : $rs->story
การปฏิบัติ : $rs->book_sign
หมายเหตุ : $rs->note ";
$strAccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$strUrl = "
https://api.line.me/v2/bot/message/push";
$arrHeader = array();
$arrHeader[] = "Content-Type: application/json";
$arrHeader[] = "Authorization: Bearer {$strAccessToken}";
$arrPostData = array();
$arrPostData['to'] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$arrPostData['messages'][0]['type'] = "text";
$arrPostData['messages'][0]['text'] = "$text";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$strUrl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arrPostData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close ($ch);
?>
<?php }
?>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
</body>
</html>
รันเสร็จ มันขึ้นว่า
Fatal error: Uncaught Error: Call to a member function fetch_object() on string in C:\xampp\htdocs\basic_php_login\webhook.php:6 Stack trace: #0 {main} thrown in C:\xampp\htdocs\basic_php_login\webhook.php on line 6
อยากรู้ว่าต้องแก้ไขยังไงครับ
line bot php
<?php include("connect.php");?>
<?php
$sql="select * from book order by id desc LIMIT 1";
$result = $conn ->query($sql);
while ($rs = $result->fetch_object()){
//echo $rs->number
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Line Bot</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="md-12 mx-auto mt-5">
<h2>บันทึกสำเร็จ</h2>
</div>
</div>
<div class="container">
<a class="btn btn-primary" href="index.php">กลับสู่หน้าหลัก</a>
</div>
<?php
$text = "เลขทะเบียนส่ง : $rs->id
ที่ : $rs->number
ลงวันที่ : $rs->date
จาก : $rs->book_from
ถึง : $rs->book_to
เรื่อง : $rs->story
การปฏิบัติ : $rs->book_sign
หมายเหตุ : $rs->note ";
$strAccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$strUrl = "https://api.line.me/v2/bot/message/push";
$arrHeader = array();
$arrHeader[] = "Content-Type: application/json";
$arrHeader[] = "Authorization: Bearer {$strAccessToken}";
$arrPostData = array();
$arrPostData['to'] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$arrPostData['messages'][0]['type'] = "text";
$arrPostData['messages'][0]['text'] = "$text";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$strUrl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arrPostData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close ($ch);
?>
<?php }
?>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
</body>
</html>
รันเสร็จ มันขึ้นว่า
Fatal error: Uncaught Error: Call to a member function fetch_object() on string in C:\xampp\htdocs\basic_php_login\webhook.php:6 Stack trace: #0 {main} thrown in C:\xampp\htdocs\basic_php_login\webhook.php on line 6
อยากรู้ว่าต้องแก้ไขยังไงครับ