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: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 63

Warning
: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 64

Warning
: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 65

Warning
: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 66

Warning
: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 67

Warning
: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 63

Warning
: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 64

Warning
: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 65

Warning
: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 66

Warning
: Trying to access array offset on value of type bool in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 67

Fatal error
: Uncaught Error: mysqli_stmt object is already closed in C:\xampp\htdocs\Innerjoin\admin\voucher.php:77 Stack trace: #0 C:\xampp\htdocs\Innerjoin\admin\voucher.php(77): mysqli_stmt->close() #1 {main} thrown in C:\xampp\htdocs\Innerjoin\admin\voucher.php on line 77

ito code ko:

<?php
if(isset($_POST['btnAdd'])){
$particular = filter_input(INPUT_POST, 'particular',FILTER_SANITIZE_STRING);
$amount = filter_input(INPUT_POST, 'amount', FILTER_SANITIZE_STRING );
$lddapada = filter_input(INPUT_POST,'lddapada',FILTER_SANITIZE_STRING );
$date = filter_input(INPUT_POST, 'date' , FILTER_SANITIZE_STRING);
$status = filter_input(INPUT_POST, 'status',FILTER_SANITIZE_STRING);
foreach($_POST['payeename'] as $index => $value){
$new_payeename = mysqli_real_escape_string($con, $value);
$new_particular = mysqli_real_escape_string($con, $particular[$index]);
$new_amount =mysqli_real_escape_string($con, $amount[$index]);
$new_lddapada = mysqli_real_escape_string($con, $lddapada[$index]);
$new_date = mysqli_real_escape_string($con, $date[$index]);
$new_status = mysqli_real_escape_string($con, $status[$index]);
$stmt=$con->prepare("INSERT INTO lddap (payee_name, particular, amount, lddap_ada, date, status) VALUES (?,?,?,?,?,?)");
$stmt->bind_param("ssssss",$new_payeename, $new_particular, $new_amount, $new_lddapada, $new_date,$new_status);
$stmt->execute();
$stmt->close();
// 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')");

}
 
The error message indicates that you are trying to access array offsets on a value of type bool in your voucher.php file. The warnings are repeated for lines 63-67. Additionally, there is a fatal error on line 77 stating that the mysqli_stmt object is already closed.

Looking at your code, it seems that the issue lies in how you are using the filter_input function and accessing the array values in the foreach loop.

Here are a few suggestions to debug and fix the issue:

1. Check if the values are being passed correctly through the form. You can use var_dump($_POST) to check the values being submitted.

2. Make sure that the input names in the HTML form match the keys used in the $_POST array. For example, name="particular[]" should correspond to $_POST['particular'].

3. Instead of using filter_input to sanitize the input values, you can directly use mysqli_real_escape_string or prepared statements to prevent SQL injection. You already have prepared statements in place, so you can remove the filter_input lines and use the escaped values directly.

4. Ensure that the $con variable is properly defined and connected to the database before executing the prepared statements.

5. Check if the array values passed in the foreach loop are indeed arrays. You can use is_array() to validate the input before accessing the array offsets.

6. To avoid the Trying to access array offset on value of type bool warnings, you can add a condition to check if the value is an array before accessing its offsets. For example:

PHP:
if (is_array($particular) && isset($particular[$index])) {
    $new_particular = mysqli_real_escape_string($con, $particular[$index]);
} else {
    // handle or skip this value
}

By following these suggestions, you should be able to resolve the warnings and fatal error in your code. Remember to always sanitize and validate user inputs to prevent security vulnerabilities.
 

Similar threads

Back
Top