What's new

Bakit kaya ganito error ko

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
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.
 

Similar threads

Back
Top