0

I got an error in this section, I don't have any ideas to fix this.

Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\web_resto\pagePelanggan.php on line 16

Notice: Undefined index: status_order in C:\xampp\htdocs\web_resto\pagePelanggan.php on line 26

Code:

<?php
include "config/controller.php";
$id = new Resto();
session_start();
$auth     = $id->AuthUser($_SESSION['username']);
$auth2    = $id->AuthPelanggan($_SESSION['username']);
$response = $id->sessionCheck();
if ($response == "false") {
    header("Location:index.php");
}
$no_meja = $auth2['no_meja'];
$sql2    = "SELECT kd_order FROM tb_order WHERE no_meja='$no_meja'";
$exe2    = mysqli_query($con, $sql2);
$num2    = mysqli_num_rows($exe2);
$dta2    = mysqli_fetch_assoc($exe2);
$data_kd = $dta2['order_kd'];
$sql3     = "SELECT status_detail FROM tb_detail_order_temporary WHERE order_kd='$data_kd'";
$exe3     = mysqli_query($con, $sql3);
$num3     = mysqli_num_rows($exe3);
$dta3     = mysqli_fetch_assoc($exe3);
$data_kd2 = $dta3['status_detail'];
$sql4     = "SELECT status_order FROM tb_order WHERE kd_order='$data_kd'";
$exe4     = mysqli_query($con, $sql4);
$num4     = mysqli_num_rows($exe4);
$dta4     = mysqli_fetch_assoc($exe4);
$data_kd3 = $dta4['status_order'];
if (isset($_GET['delete'])) {
    if ($data_kd3 == "belum_beli") {
?>
      
halfer
  • 19,824
  • 17
  • 99
  • 186
sabo tase
  • 9
  • 3
  • Please understand what the message actually says. This is a _notice_ from a logical point of view, not an error. You try to access an element of an array which does not exist. That is all. – arkascha Aug 07 '21 at 09:41
  • Don't post [images of code](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question)! – brombeer Aug 07 '21 at 09:59
  • Does this answer your question? ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – Tim Yao Aug 07 '21 at 12:14
  • It is a notice and not an error. – Asuquo12 Aug 07 '21 at 21:34

1 Answers1

2

There are many things wrong with your code, but the issue, at this moment, is that your query is:

SELECT kd_order FROM tb_order WHERE no_meja='$no_meja'

but in your PHP code you ask for:

$data_kd = $dta2['order_kd'];

You have kd_order in your query, but you use order_kd as the index. That will never work.

Other (major) problems are:

If you enjoy PHP, have a look at this website: PHP: The Right Way

KIKO Software
  • 15,283
  • 3
  • 18
  • 33