Based on the code you provided, it seems that the issue lies in the way you are fetching and inserting the values into the database.
In your code, you are using the
mysqli_real_escape_string
function on static strings instead of the actual values from the form input. This is why you're seeing the unexpected characters in the database.
To fix this issue, you need to update your code to correctly fetch the values from the form inputs and use those values in the
mysqli_real_escape_string
function.
Here's an updated version of your code:
PHP:
<?php
if(isset($_POST['btnAdd'])){
$stmt = $con->prepare("INSERT INTO lddap (payee_name, particular, amount, lddap_ada, date, status) VALUES (?, ?, ?, ?, ?, ?)");
foreach($_POST['payeename'] as $index => $value){
$payeename = mysqli_real_escape_string($con, $value);
$particular = mysqli_real_escape_string($con, $_POST['particular'][$index]);
$amount = mysqli_real_escape_string($con, $_POST['amount'][$index]);
$lddapada = mysqli_real_escape_string($con, $_POST['lddapada'][$index]);
$date = mysqli_real_escape_string($con, $_POST['date'][$index]);
$status = mysqli_real_escape_string($con, $_POST['status'][$index]);
$stmt->bind_param("ssssss", $payeename, $particular, $amount, $lddapada, $date, $status);
$stmt->execute();
}
$stmt->close();
echo "<script>window.location.href = 'voucher.php?notify=items uploaded';</script>";
}
?>
In this code, we fetch the values from the form inputs using the
$_POST
superglobal array and index them using the
$index
variable from the foreach loop. This ensures that the correct values are inserted into the database.
Make sure to update the form element names in the HTML to match the keys used in the
$_POST
array.
ito error
Warning: Undefined array key "$particular" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
68
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
68
Warning: Undefined array key "$amount" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
69
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
69
Warning: Undefined array key "$lddapada" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
70
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
70
Warning: Undefined array key "$date" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
71
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
71
Warning: Undefined array key "$status" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
72
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
72
Warning: Undefined array key "$particular" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
68
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
68
Warning: Undefined array key "$amount" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
69
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
69
Warning: Undefined array key "$lddapada" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
70
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
70
Warning: Undefined array key "$date" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
71
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
71
Warning: Undefined array key "$status" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
72
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
72
Warning: Undefined array key "$particular" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
68
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
68
Warning: Undefined array key "$amount" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
69
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
69
Warning: Undefined array key "$lddapada" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
70
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
70
Warning: Undefined array key "$date" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
71
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
71
Warning: Undefined array key "$status" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
72
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
72
Warning: Undefined array key "$particular" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
68
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
68
Warning: Undefined array key "$amount" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
69
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
69
Warning: Undefined array key "$lddapada" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
70
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
70
Warning: Undefined array key "$date" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
71
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
71
Warning: Undefined array key "$status" in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
72
Warning: Trying to access array offset on value of type null in
C:\xampp\htdocs\Innerjoin\admin\voucher.php on line
72