🔒 Closed Bakit kaya ganito error ko

Status
Not open for further replies.

loktoy

Established
Warning: Undefined array key 7 in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 61

Warning
: Undefined array key 8 in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 57

Warning
: Undefined array key 8 in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 59

Warning
: Undefined array key 8 in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 60

ito code ko

if(isset($_POST['btnAdd'])){
$unique_payeename = array_unique($_POST['payeename']);
$unique_particular = array_unique($_POST['particular']);
$unique_amount = array_unique($_POST['amount']);
$unique_lddapada = array_unique($_POST['lddapada']);
$unique_date = array_unique($_POST['date']);
$unique_status = array_unique($_POST['status']);
foreach($unique_payeename as $index => $value){
$new_payeename = $value;
$new_particular = $unique_particular[$index];
$new_amount = $unique_amount[$index];
$new_lddapada = $unique_lddapada[$index];
$new_date = $unique_date[$index];
$new_status = $unique_status[$index];
mysqli_query($con, "INSERT INTO lddap (payee_name, particular, amount, lddap_ada, date, status) VALUES ('$new_payeename', '$new_particular', '$new_amount', '$new_lddapada', '$new_date', '$new_status')");
echo "<script> window.location.href = voucher.php?notify=<font color=green>items uploaded</font>';</script>";
}
}
 
The error you are encountering is caused by accessing an undefined array key. Specifically, the error is occurring at lines 61, 57, 59, and 60 of the voucher.php file.

To fix this issue, you need to ensure that the array keys you are accessing exist. One way to do this is by checking if the array key exists before accessing it.

Here's an updated version of your code with the necessary checks:

PHP:
if(isset($_POST['btnAdd'])){
    $unique_payeename = array_unique($_POST['payeename']);
    $unique_particular = array_unique($_POST['particular']);
    $unique_amount = array_unique($_POST['amount']);
    $unique_lddapada = array_unique($_POST['lddapada']);
    $unique_date = array_unique($_POST['date']);
    $unique_status = array_unique($_POST['status']);

    foreach($unique_payeename as $index => $value){
        $new_payeename = $value;

        // Check if the array key exists before accessing it
        $new_particular = isset($unique_particular[$index]) ? $unique_particular[$index] : '';
        $new_amount = isset($unique_amount[$index]) ? $unique_amount[$index] : '';
        $new_lddapada = isset($unique_lddapada[$index]) ? $unique_lddapada[$index] : '';
        $new_date = isset($unique_date[$index]) ? $unique_date[$index] : '';
        $new_status = isset($unique_status[$index]) ? $unique_status[$index] : '';

        mysqli_query($con, "INSERT INTO lddap (payee_name, particular, amount, lddap_ada, date, status) VALUES ('$new_payeename', '$new_particular', '$new_amount', '$new_lddapada', '$new_date', '$new_status')");
        echo "<script> window.location.href = voucher.php?notify=<font color=green>items uploaded</font>';</script>";
    }
}
By using the isset() function, you can check if the array key exists before accessing it. If the key does not exist, you can assign a default value or handle the situation accordingly.

Make sure to replace the existing code with the updated version provided above. This should resolve the error you are experiencing.
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 352
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,162
Guests online
4,532
Total visitors
5,694

Forum statistics

Threads
2,313,196
Posts
29,172,338
Members
1,184,631
Latest member
DylanSama
Back
Top