Skip to main content

upload.php for the app for uploading the excel sheet in kdp data of samudra

<?php

include("../header.php");

require("connect.php");


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

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


    $ext = pathinfo($_FILES['doc']['name'], PATHINFO_EXTENSION);

    if ($ext == 'xlsx' or 'XLSX') {

        require('PHPExcel/PHPExcel.php');

        require('PHPExcel/PHPExcel/IOFactory.php');



        $obj = PHPExcel_IOFactory::load($file);

        foreach ($obj->getWorksheetIterator() as $sheet) {

            $getHighestRow = $sheet->getHighestRow();

            for ($i = 0; $i <= $getHighestRow; $i++) {

                $bmc = $sheet->getCellByColumnAndRow(0, $i)->getValue();

                $route = $sheet->getCellByColumnAndRow(1, $i)->getValue();

                $society = $sheet->getCellByColumnAndRow(2, $i)->getValue();

                $date = $sheet->getCellByColumnAndRow(3, $i)->getValue();

                $shift = $sheet->getCellByColumnAndRow(4, $i)->getValue();

                $sample = $sheet->getCellByColumnAndRow(5, $i)->getValue();

                $cate = $sheet->getCellByColumnAndRow(6, $i)->getValue();

                $type = $sheet->getCellByColumnAndRow(7, $i)->getValue();

                $qty = $sheet->getCellByColumnAndRow(8, $i)->getValue();

                $fat0 = $sheet->getCellByColumnAndRow(9, $i)->getValue();

                $snf0 = $sheet->getCellByColumnAndRow(10, $i)->getValue();

                $lr = $sheet->getCellByColumnAndRow(11, $i)->getValue();

                $rcan = $sheet->getCellByColumnAndRow(12, $i)->getValue();

                $acan = $sheet->getCellByColumnAndRow(13, $i)->getValue();

                $bmc0 = substr($bmc, 1);

                $bmc1 = strtok($bmc0, ']'); //yaha 1801 bmc number aayega

                $route0 = substr($route, 1);

                $route1 = strtok($route0, ']'); //yaha route code aayega

                $route2 = strstr($route, ' '); //yaha route name aayega

                $society0 = substr($society, 1);

                $society1 = strtok($society0, ']'); //yaha society code milega 

                $society2 = strstr($society, ' '); //yaha society name milega

                $date0 = str_replace("/", "-", $date);

                $date1 = date("Y-m-d", strtotime($date0));//yaha date aayega

                $fat=number_format((float)$fat0, 1, '.', '');

                $snf=number_format((float)$snf0, 1, '.', ''); 

                if ($date != '') {

                    $query="INSERT INTO `samudra`(`bmccode`, `routecode`, `routename`, `societycode`, `societyname`, `date`, `shift`, `sampleno`, `qty`, `fat`, `snf`, `grade`,`cate`,`acan`, `status`) VALUES ('$bmc1','$route1','$route2','$society1','$society2','$date1','$shift','$sample','$qty','$fat','$snf','$type','$cate','$acan','0')";

                    mysqli_query($con,$query);

                }

                elseif ($date == ''){

                    echo "<script>alert('Details added successfully');

                 window.location.href='upload.php'</script>";

                }


                

            }

        }

    } else {

        echo "<script>alert('Invalid file format')</script>";

    }

}

?>

<div>

    

</div>

<div class="container-fluid pt-4 px-4 scroll" style="overflow: scroll;">

    <div style="padding: 2% 3%;" class=" bg-light rounded align-items-center justify-content-center mx-0">

        <form method="post" enctype="multipart/form-data">

            <div class="mb-3">

                <label for="exampleInputEmail1" class="form-label">Choose the File</label>

                <input type="file" name="doc" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">

            </div>

            <button type="submit" name="samudra" class="btn btn-primary">Submit</button>

        </form>

    </div>

    <div style="padding: 2% 3%;" class=" bg-light rounded align-items-center justify-content-center mx-0">

        <form method="post" action="bmcdata.php">

            <?php

            $query00 = " SELECT * from `samudra` where `status`=0";

            $res00 = mysqli_query($con, $query00);

            $row00 = mysqli_num_rows($res00);

            ?>

            <div style="display: flex;">

                <div class="mb-3" style="margin-right: 10%;">

                    <label for="exampleInputEmail1" class="form-label">Plant</label>

                    <select class="form-select" name="plant" required aria-label="Default select example">

                        <option selected></option>

                        <option value="1801">1801</option>

                        <option value="1802">1802</option>

                        <option value="1806">1806</option>

                        <option value="1807">1807</option>

                        <option value="1808">1808</option>

                        <option value="1809">1809</option>

                        <option value="1810">1810</option>

                        <option value="1811">1811</option>

                        <option value="1812">1812</option>

                        <option value="1851">1851</option>

                        <option value="1852">1852</option>

                    </select>

                </div>

                <div class="mb-3" style="margin-right: 10%;">

                    <label for="exampleInputEmail1" class="form-label">Date</label>

                    <input type="date" name="date" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">

                </div>

                <div class="mb-3">

                    <label for="exampleInputEmail1" class="form-label">Shift</label>

                    <select class="form-select" name="shift" required aria-label="Default select example">

                        <option selected></option>

                        <option value="Morning">Morning</option>

                        <option value="Evening">Evening</option>

                        <option value="Both">Both</option>

                    </select>

                </div>

            </div>

            <button type="submit" name="updatekg" class="btn btn-primary">Update <?php echo $row00 ?> rows values </button>

        </form>

    </div>

</div>


<?php

include("../footer.php");

?>

Comments

Popular posts from this blog

How to add the treeview numbers to get the grand total in tkinter entry box

 in this blog we are going to know about the adding of the integers in the treeview and get the total in the entry box of tkinter so here is the image first so the coding to do such things are here as follow but here is the condition that pls make assured that the state of entry box is disabled.......      for child in my_tree1 . get_children ():         e2l . config ( state = "normal" )         b1 += float ( my_tree1 . item ( child , "values" )[ 3 ])         var2 . set ( b1 )         e2l . config ( state = "disable" )      l2l = Label ( ento , text = "Purnea-2" , width = 8 )      l2l . grid ( row = 0 , column = 1 )     e2l = Entry ( ento , textvariable = var2 , state = "disable" , width = 8 )     e2l . grid ( row = 1 , column = 1 )