What's new

Bakit kaya ganun yun database ko

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
kapag nag iimport ako ng excel so pumapasok sya sa database pero yun ibang details ay wala at yun iba naman ay kompleto yun details..

ito code ko.
<?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;
$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>";
}
}
if(isset($_POST['btnUpload'])){
echo "<hr>";
echo "<table border='1' width='40%'>";
echo "<tr>
<td width='70%'><b>Payee Name</b></td>
<td width='70%'><b>Particular</b></td>
<td width='70%'><b>Amount</b></td>
<td width='70%'><b>LDDAP-ADA</b></td>
<td width='70%'><b>Date</b></td>
<td width='70%'><b>Status</b></td>
</tr>
<tr>
<td colspan='2'><hr></td>
</tr>

<form method = 'POST'>

";

$btnStatus = "ENABLED";
$filename = $_FILES['file']['tmp_name'];
if($_FILES['file']['size'] > 0) {

$file = fopen($filename, "r");

$row = 1;
$payeename = $particular = $amount = $lddapada = $date = $status = "";
$payeenameErr = $particularErr = $amountErr = $lddapadaErr = $dateErr = $statusErr = "";
while (($data = fgetcsv($file, 10000, ",")) !== false){

if($row == 1){
$row++;
continue;
}
if(empty($data[0])){
$payeenameErr = "Product name is empty";
$btnStatus = "DISABLED";
}else {
$payeename = $data[0];
}
if(empty($data[1])){
$particularErr = "Product name is empty";
$btnStatus = "DISABLED";
}else {
$particular = $data[1];
}
if(empty($data[2])){
$amountErr = "Product name is empty";
$btnStatus = "DISABLED";
}else {
$amount = $data[2];
}
if(empty($data[3])){
$lddapadaErr = "Product name is empty";
$btnStatus = "DISABLED";
}else {
$lddapada = $data[3];
}
if(empty($data[4])){
$dateErr = "Product name is empty";
$btnStatus = "DISABLED";
}else {
$date = $data[4];
}
if(empty($data[5])){
$statusErr = "Product name is empty";
$btnStatus = "DISABLED";
}else {
$status = $data[5];
}
echo "<input type = 'hidden' name = 'payeename[]' value ='$payeename'>";
echo "<input type = 'hidden' name = 'particular[]' value ='$particular'>";
echo "<input type = 'hidden' name = 'amount[]' value = '$amount'>";
echo "<input type = 'hidden' name = 'lddapada[]' value = '$lddapada'>";
echo "<input type = 'hidden' name = 'date[]' value = '$date'>";
echo "<input type = 'hidden' name = 'status[]' value = '$status'>";
echo "<tr>
<td>$payeename</td>
<td>$particular</td>
<td>$amount</td>
<td>$lddapada</td>
<td>$date</td>
<td>$status</td>

</tr>";
}
}
echo "<tr>
<td width='100%'>
<div align ='center'>
<input type = 'submit' $btnStatus name = 'btnAdd' value = 'Add this item'>
</div>
</td>
</tr>

</form>

";

echo "</table>";
}

?>
 
Based on your code, it seems that you are importing data from an Excel file into your database. However, you mentioned that some details are missing while others are complete.

One possible reason for this issue could be the way you are handling the data in your code. In particular, when you are iterating through the rows of the Excel file, you are checking for empty values in each column and setting error messages and the button status accordingly. However, even if a column is empty, you are still adding the values to the corresponding arrays and inserting them into the database later on.

To fix this issue, you should only add the values to the arrays and insert them into the database if all the required fields are not empty. You can modify your code as follows:

Code:
while (($data = fgetcsv($file, 10000, ",")) !== false) {
    if ($row == 1) {
        $row++;
        continue;
    }

    $payeename = $data[0];
    $particular = $data[1];
    $amount = $data[2];
    $lddapada = $data[3];
    $date = $data[4];
    $status = $data[5];

    if (empty($payeename) || empty($particular) || empty($amount) || empty($lddapada) || empty($date) || empty($status)) {
        $btnStatus = "DISABLED";
    } else {
        echo "<input type='hidden' name='payeename[]' value='$payeename'>";
        echo "<input type='hidden' name='particular[]' value='$particular'>";
        echo "<input type='hidden' name='amount[]' value='$amount'>";
        echo "<input type='hidden' name='lddapada[]' value='$lddapada'>";
        echo "<input type='hidden' name='date[]' value='$date'>";
        echo "<input type='hidden' name='status[]' value='$status'>";

        echo "<tr>
            <td>$payeename</td>
            <td>$particular</td>
            <td>$amount</td>
            <td>$lddapada</td>
            <td>$date</td>
            <td>$status</td>
        </tr>";
    }
    $row++;
}

With this modification, the values will only be added to the arrays and inserted into the database if all the required fields are not empty.

Additionally, it's important to note that your current code is vulnerable to SQL injection attacks. You should consider using prepared statements or sanitizing the input to protect your database from malicious attacks.
 
Based on your code, it seems that you are importing data from an Excel file into your database. However, you mentioned that some details are missing while others are complete.

One possible reason for this issue could be the way you are handling the data in your code. In particular, when you are iterating through the rows of the Excel file, you are checking for empty values in each column and setting error messages and the button status accordingly. However, even if a column is empty, you are still adding the values to the corresponding arrays and inserting them into the database later on.

To fix this issue, you should only add the values to the arrays and insert them into the database if all the required fields are not empty. You can modify your code as follows:

Code:
while (($data = fgetcsv($file, 10000, ",")) !== false) {
    if ($row == 1) {
        $row++;
        continue;
    }

    $payeename = $data[0];
    $particular = $data[1];
    $amount = $data[2];
    $lddapada = $data[3];
    $date = $data[4];
    $status = $data[5];

    if (empty($payeename) || empty($particular) || empty($amount) || empty($lddapada) || empty($date) || empty($status)) {
        $btnStatus = "DISABLED";
    } else {
        echo "<input type='hidden' name='payeename[]' value='$payeename'>";
        echo "<input type='hidden' name='particular[]' value='$particular'>";
        echo "<input type='hidden' name='amount[]' value='$amount'>";
        echo "<input type='hidden' name='lddapada[]' value='$lddapada'>";
        echo "<input type='hidden' name='date[]' value='$date'>";
        echo "<input type='hidden' name='status[]' value='$status'>";

        echo "<tr>
            <td>$payeename</td>
            <td>$particular</td>
            <td>$amount</td>
            <td>$lddapada</td>
            <td>$date</td>
            <td>$status</td>
        </tr>";
    }
    $row++;
}

With this modification, the values will only be added to the arrays and inserted into the database if all the required fields are not empty.

Additionally, it's important to note that your current code is vulnerable to SQL injection attacks. You should consider using prepared statements or sanitizing the input to protect your database from malicious attacks.
pumapasok naman sya sa database ko kaso walang laman yun iba
 
pumapasok naman sya sa database ko kaso walang laman yun iba
If some of the details are not being inserted into the database, there could be a couple of reasons for this issue:

1. Empty or missing values in the Excel file: Make sure that the corresponding cells in the Excel file contain the required values for all the fields. If any of the cells are empty or have missing data, those values will not be added to the arrays and will not be inserted into the database.

2. Index mismatch in the arrays: Check if the indices of the arrays $unique_payeename, $unique_particular, $unique_amount, $unique_lddapada, $unique_date, and $unique_status are aligned properly. Each index should correspond to the same row of data from the Excel file. If the indices are not aligned correctly, the data may not be inserted correctly into the database.

To troubleshoot the issue and identify which specific data is missing, you can add some debug statements in your code. For example, you can add the following code inside the foreach loop to print the values before inserting them into the database:

PHP:
echo "Payee Name: " . $new_payeename . "<br>";
echo "Particular: " . $new_particular . "<br>";
echo "Amount: " . $new_amount . "<br>";
echo "LDDAP-ADA: " . $new_lddapada . "<br>";
echo "Date: " . $new_date . "<br>";
echo "Status: " . $new_status . "<br>";

This will help you identify if any specific values are missing or not being assigned properly.

Additionally, it's important to note that your current code is vulnerable to SQL injection attacks. You should consider using prepared statements or sanitizing the input to protect your database from malicious attacks.
 

Similar threads

Back
Top