|
 |
|
error การบันทึกข้อมูลระบบทำงานปกติ แต่มี code error หาแนวทางการเขียน code ดัก error |
|
 |
|
|
 |
 |
|
เปลี่ยน $result เป็น $query->num_rows
if( $query->num_rows ){
$result=$query->fetch_assoc();
$query มันไม่เกิด error เพียงแต่มัน ไม่มี record ให้ใช้งาน
เมื่อไม่มี record แต่ ไป fetch มันออกมา จึงเกิด error
|
ประวัติการแก้ไข 2024-04-12 16:30:58 2024-04-12 16:33:06 2024-04-12 16:34:27
 |
 |
 |
 |
Date :
2024-04-12 16:30:31 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
undefined array key "code"
ใช้ isset, หรือ arry_key_exists ดักก่อนเรียก
ระวังการใช้ isset ถ้ามันเป็น null ก็จะถือว่าไม่ได้ set
https://www.php.net/manual/en/function.isset.php
การใช้ array_key_exists จะตรวจแค่ว่ามี key อยู่หรือไม่เท่านั้นไม่เหมือน isset
บางกรณีเราต้องตรวจแค่ว่ามี array key หรือไม่ก็ใช้ฟังก์ชั่นนี้
ตย.
Code (PHP)
$array = array(
'hello' => null,
);
var_dump(array_key_exists('hello', $array));// true
var_dump(isset($array['hello']));// false
https://www.php.net/manual/en/function.array-key-exists.php
|
ประวัติการแก้ไข 2024-04-12 20:08:10
 |
 |
 |
 |
Date :
2024-04-12 20:07:49 |
By :
mr.v |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|