What's new

Bakit ganito insert nya

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
ang inuupload ko ganito yun format nya:


sample tubig 10 2 8/23/2023 ρáíd
sample kuryente 10 2 8/2/2023 ρáíd
sample kuryente 10 2 8/16/2023 ρáíd
sample kuryente 10 2 7/8/2023 ρáíd

pero ngayon ganito na ang nasa database ko kapag pinasok ko na sya.

sample p a l d s
sample a m d a t
sample r o d t a
sample t u a e t

ito code ko:

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


}
$stmt->close();
echo "<script> window.location.href = voucher.php?notify = <font color= green>items uploaded</font>';</script>";
}
 
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.
 
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
 

Similar threads

Back
Top