As you can see the name of input type name is excel and it said Undefined index. I already upload a file
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{
}
}