I'm doing a very simple project for my assignment and it's about shopping cart. I've created a cart page by using SESSION with array and index to keep track user's order. The problem is whenever I'm deleting a meal from my cart list, there'll be an error which is "Notice: Undefined offset: 1", "Notice: Undefined offset: 2", etc. I'm attaching my codes here:
This is my cart page. The error said it has something to do on the line that I have commented:
<form method="POST" action="save_cart.php">
<table class="table">
<tbody>
<thead>
      <th></th>
      <th>Name</th>
      <th>Price</th>
      <th>Quantity</th>
      <th>Subtotal</th>
</thead>
  <?php
        //initialize total
        $total = 0;
        if(!empty($_SESSION['cart'])){
        //create array of initail qty which is 1
        $index = 0;
        if(!isset($_SESSION['qty_array'])){
          $_SESSION['qty_array'] = array_fill(0, count($_SESSION['cart']), 1);
        }
        $sql = "SELECT * FROM meal WHERE meal_id IN (".implode(',',$_SESSION['cart']).")";
        $query = $conn->query($sql);
          while($row = $query->fetch_assoc()){
            ?>
          <tr>
              <td class="removebtn" style="text-align: center;">
                <a href="delete_item.php?id=<?php echo $row['meal_id']; ?>&index=<?php echo $index; ?>" >Remove</a>
              </td>
              <td><?php echo $row['meal_name']; ?></td>
              <td>RM <?php echo number_format($row['meal_price'], 2); ?></td>
              <input type="hidden" name="indexes[]" value="<?php echo $index; ?>">
              <td class="qtyinput" ><input type="number" min="1" max="5" class="form-control" value="<?php echo $_SESSION['qty_array'][$index]; ?>" name="qty_<?php echo $index; ?>"></td>
              //THE ERROR IS HERE
              <td>RM <?php echo number_format($_SESSION['qty_array'][$index]*$row['meal_price'], 2); ?></td>
              <?php $total += $_SESSION['qty_array'][$index]*$row['meal_price']; ?>
            </tr>
            <?php
            $index ++;
          }
        }
        else{
          ?>
          <tr>
            <td colspan="5" class="text-center"  style="text-align: center;">No Meal in Cart</td>
          </tr>
          <?php
        }
      ?>
      <tr>
        <td colspan="4" align="left"><b>Total</b></td>
        <td><b>RM <?php echo number_format($total, 2); ?></b></td>
      </tr>
</tr>
Here's my delete page:
session_start();
//remove the id from our cart array
$key = array_search($_GET['meal_id'], $_SESSION['cart']);   
unset($_SESSION['cart'][$key]);
unset($_SESSION['qty_array'][$_GET['index']]);
//rearrange array after unset
$_SESSION['qty_array'] = array_values($_SESSION['qty_array']);
$_SESSION['message'] = "<script>alert('Meal is deleted from your cart');</script>";
header('location: cart.php');
I really need your help. Thanks in advance!

 
    