0

As you can see the name of input type name is excel and it said Undefined index. I already upload a file

excel.csv

but It's same. I don't know what the problem is.I already check all and retype the input type name to make sure it is not mispelled words or what. Thank you

booky.php

<?php include('dbcon.php'); ?>
<html>

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

        <input type="file" name="excel" class="btn btn"/>
        <input type="submit" name="submit" value="Import" />

        <?php include('import/phpimport.php'); ?>

    </form>
</html>

phpimport.php

<?php include('../dbcon.php');

if(isset($_POST["submit"])){

    $file_name = $_FILES["excel"]["name"];

    $array = explode('.', $file_name);
    $extension = end($array); // For getting Extension of selected file
    $allowed_extension = array("xls", "xlsx", "csv"); //allowed extension
    if(in_array($extension, $allowed_extension)) //check selected file extension is present in allowed extension array
    {

        $file = $_FILES["excel"]["tmp_name"]; // getting temporary source of excel file
        include("Classes/PHPExcel/IOFactory.php"); // Add PHPExcel Library in this code 
        $objPHPExcel = PHPExcel_IOFactory::load($file); // create object of PHPExcel library by using load() method and in load method define path of selected file

        foreach ($objPHPExcel->getWorksheetIterator() as $worksheet){
            $highestRow = $worksheet->getHighestRow();
            for($row=0; $row<=$highestRow; $row++){

                $accession = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(0, $row)->getValue());
                $book_title = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(1, $row)->getValue());
                $author = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(2, $row)->getValue());
                $publisher = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(3, $row)->getValue());
                $year = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(4, $row)->getValue());
                $isbn = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(5, $row)->getValue());

                mysqli_query("INSERT INTO book(book_id,book_title,author,publisher,isbn,year) VALUES($accession,$book_title,$author,$publisher,$year,$isbn)");

            }
        }                       
    }else{

     }
}
  • Are you sure that's the same `phpimport.php` file as on your server? I only ask as line #7 does not any mention of `"excel"` – Phil Aug 28 '17 at 04:17
  • Also, you are including `dbcon.php` twice. I suggest using `require_once` instead of `include`. In fact, when included from `booky.php`, `phpimport.php` won't be able to include `../dbcon.php` as the path is incorrect. Use `require_once __DIR__ . '/../dbcon.php';` – Phil Aug 28 '17 at 04:18
  • Once you fix whatever is causing this, you're going to run into SQL query problems with your un-quoted string values. I suggest you read this and use a prepared statement ~ php.net/manual/en/mysqli.quickstart.prepared-statements.php – Phil Aug 28 '17 at 04:20
  • Voting to close as a *typo*. You have `encpart` in your `
    ` tag where it should be `enctype`
    – Phil Aug 28 '17 at 04:24

0 Answers0