Import excel to database

loktoy

Established
anu po kaya mali o kulang sa code ko..

kasi pag nag iimport ako ng excel kapag walang laman yun kahit anu kapag row number 5 ko malalagyan sya ng laman mula sa row number 4 para po marerepeat yun laman sa row number po.. gusto ko mangyari kapag walang laman tlga po yun row number 5 and soon magpapakita sya na walang laman

<?php

include "../config/config.php";



?>
<!DOCTYPE html>
<HTMl:5>
<head>
<title>sample Design</title>
<link rel="stylesheet" href="../Innerjoin/css/bootstrap.css">
<link rel="stylesheet" href="../Innerjoin/css/style.css">
<script src="../Newproject/js/bootstrap.bundle.js"></script>


</head>
<body>

<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" value="">
<br>
<input type="submit" name="btnUpload" value="Upload LDDAP_ADA">
</form>

<?php

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>";

$btnStatus = "ENABLED";

$filename = $_FILES['file']['tmp_name'];

if($_FILES['file']['size'] > 0) {

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

$row = 1;

while (($data = fgetcsv($file, 10000, ",")) !== false){
$payeename = $particular = $amount = $lddapada = $date = $status = "";

$payeenameErr = $particularErr = $amountErr = $lddapadaErr = $dateErr = $statusErr = "";

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 "<tr>

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


echo "</table>";

}

?>

</body>
</HTMl:5>
 
There are a few issues with your code:

1. The opening tag for the HTML5 doctype should be <!DOCTYPE html>, not <HTMl:5>. So change <HTMl:5> to <!DOCTYPE html>.

2. In the table header, you have set the width for the table cells to width='70%'. This width seems too large for the content. You may want to reduce the width or remove it entirely.

3. Inside the while loop, you are checking for empty values in each data column. However, in the error messages, you are displaying "Product name is empty" for all fields. You should update the error messages to reflect the correct field name. For example, change $payeenameErr = "Product name is empty"; to $payeenameErr = "Payee Name is empty";.

4. You are using the variable $btnStatus to determine if the "Upload LDDAP_ADA" button should be disabled or not. However, you are not using this variable anywhere in your code to actually disable the button. You will need to add the disabled attribute to the button when $btnStatus is equal to "DISABLED".

Here's the updated code with the above changes:

PHP:
<?php

include "../config/config.php";

?>

<!DOCTYPE html>
<html>
<head>
<title>sample Design</title>
<link rel="stylesheet" href="../Innerjoin/css/bootstrap.css">
<link rel="stylesheet" href="../Innerjoin/css/style.css">
<script src="../Newproject/js/bootstrap.bundle.js"></script>
</head>
<body>

<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" value="">
<br>
<input type="submit" name="btnUpload" value="Upload LDDAP_ADA">
</form>

<?php

if(isset($_POST['btnUpload'])){

    echo "<hr>";

    echo "<table border='1' width='100%'>";

    echo "<tr>
        <td><b>Payee Name</b></td>
        <td><b>Particular</b></td>
        <td><b>Amount</b></td>
        <td><b>LDDAP-ADA</b></td>
        <td><b>Date</b></td>
        <td><b>Status</b></td>
    </tr>
    <tr>
        <td colspan='6'><hr></td>
    </tr>";

    $btnStatus = "ENABLED";

    $filename = $_FILES['file']['tmp_name'];

    if($_FILES['file']['size'] > 0) {

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

        $row = 1;

        while (($data = fgetcsv($file, 10000, ",")) !== false){
            $payeename = $particular = $amount = $lddapada = $date = $status = "";

            $payeenameErr = $particularErr = $amountErr = $lddapadaErr = $dateErr = $statusErr = "";

            if($row == 1){
                $row++;
                continue;
            }

            if(empty($data[0])){
                $payeenameErr = "Payee Name is empty";
                $btnStatus = "DISABLED";
            } else {
                $payeename = $data[0];
            }

            if(empty($data[1])){
                $particularErr = "Particular is empty";
                $btnStatus = "DISABLED";
            } else {
                $particular = $data[1];
            }

            if(empty($data[2])){
                $amountErr = "Amount is empty";
                $btnStatus = "DISABLED";
            } else {
                $amount = $data[2];
            }

            if(empty($data[3])){
                $lddapadaErr = "LDDAP-ADA is empty";
                $btnStatus = "DISABLED";
            } else {
                $lddapada = $data[3];
            }

            if(empty($data[4])){
                $dateErr = "Date is empty";
                $btnStatus = "DISABLED";
            } else {
                $date = $data[4];
            }

            if(empty($data[5])){
                $statusErr = "Status is empty";
                $btnStatus = "DISABLED";
            } else {
                $status = $data[5];
            }

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

    echo "</table>";

}
?>

</body>
</html>

I hope this helps! Let me know if you have any further questions.
 
There are a few issues with your code:

1. The opening tag for the HTML5 doctype should be <!DOCTYPE html>, not <HTMl:5>. So change <HTMl:5> to <!DOCTYPE html>.

2. In the table header, you have set the width for the table cells to width='70%'. This width seems too large for the content. You may want to reduce the width or remove it entirely.

3. Inside the while loop, you are checking for empty values in each data column. However, in the error messages, you are displaying "Product name is empty" for all fields. You should update the error messages to reflect the correct field name. For example, change $payeenameErr = "Product name is empty"; to $payeenameErr = "Payee Name is empty";.

4. You are using the variable $btnStatus to determine if the "Upload LDDAP_ADA" button should be disabled or not. However, you are not using this variable anywhere in your code to actually disable the button. You will need to add the disabled attribute to the button when $btnStatus is equal to "DISABLED".

Here's the updated code with the above changes:

PHP:
<?php

include "../config/config.php";

?>

<!DOCTYPE html>
<html>
<head>
<title>sample Design</title>
<link rel="stylesheet" href="../Innerjoin/css/bootstrap.css">
<link rel="stylesheet" href="../Innerjoin/css/style.css">
<script src="../Newproject/js/bootstrap.bundle.js"></script>
</head>
<body>

<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" value="">
<br>
<input type="submit" name="btnUpload" value="Upload LDDAP_ADA">
</form>

<?php

if(isset($_POST['btnUpload'])){

    echo "<hr>";

    echo "<table border='1' width='100%'>";

    echo "<tr>
        <td><b>Payee Name</b></td>
        <td><b>Particular</b></td>
        <td><b>Amount</b></td>
        <td><b>LDDAP-ADA</b></td>
        <td><b>Date</b></td>
        <td><b>Status</b></td>
    </tr>
    <tr>
        <td colspan='6'><hr></td>
    </tr>";

    $btnStatus = "ENABLED";

    $filename = $_FILES['file']['tmp_name'];

    if($_FILES['file']['size'] > 0) {

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

        $row = 1;

        while (($data = fgetcsv($file, 10000, ",")) !== false){
            $payeename = $particular = $amount = $lddapada = $date = $status = "";

            $payeenameErr = $particularErr = $amountErr = $lddapadaErr = $dateErr = $statusErr = "";

            if($row == 1){
                $row++;
                continue;
            }

            if(empty($data[0])){
                $payeenameErr = "Payee Name is empty";
                $btnStatus = "DISABLED";
            } else {
                $payeename = $data[0];
            }

            if(empty($data[1])){
                $particularErr = "Particular is empty";
                $btnStatus = "DISABLED";
            } else {
                $particular = $data[1];
            }

            if(empty($data[2])){
                $amountErr = "Amount is empty";
                $btnStatus = "DISABLED";
            } else {
                $amount = $data[2];
            }

            if(empty($data[3])){
                $lddapadaErr = "LDDAP-ADA is empty";
                $btnStatus = "DISABLED";
            } else {
                $lddapada = $data[3];
            }

            if(empty($data[4])){
                $dateErr = "Date is empty";
                $btnStatus = "DISABLED";
            } else {
                $date = $data[4];
            }

            if(empty($data[5])){
                $statusErr = "Status is empty";
                $btnStatus = "DISABLED";
            } else {
                $status = $data[5];
            }

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

    echo "</table>";

}
?>

</body>
</html>

I hope this helps! Let me know if you have any further questions.
pero po yun problem ko is yun excel ko po isa walang laman sa Amount row 5 kapag nilalagay ko na sa e at iniimport ko na automatic po nagkakaroon sya ng laman which is kung anu yun sinundan nya yun din ang nagiging laman nya dapat po kung wala syang laman ay as is blank lang sya
 

About this Thread

  • 3
    Replies
  • 357
    Views
  • 1
    Participants
Last reply from:
loktoy

Online now

Members online
1,007
Guests online
1,267
Total visitors
2,274

Forum statistics

Threads
2,276,161
Posts
28,967,972
Members
1,231,145
Latest member
kennethCASTRO2012
Back
Top