File: /home/u435929562/domains/events.peacockindia.in/public_html/admin/import.php
<?php
$servername = "localhost";
$username = "u520518518_valoevent_demo";
$password = "Valoevent@dem0";
$dbname = "u520518518_valoevent_demo";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// echo "connected";
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Common\Type;
// Include Spout library
require_once 'spout/src/Spout/Autoloader/autoload.php';
// check file name is not empty
if (!empty($_FILES['file']['name'])) {
// Get File extension eg. 'xlsx' to check file is excel sheet
$pathinfo = pathinfo($_FILES["file"]["name"]);
// check file has extension xlsx, xls and also check
// file is not empty
if (($pathinfo['extension'] == 'xlsx' || $pathinfo['extension'] == 'xls')
&& $_FILES['file']['size'] > 0 ) {
// Temporary file name
$inputFileName = $_FILES['file']['tmp_name'];
// Read excel file by using ReadFactory object.
$reader = ReaderFactory::create(Type::XLSX);
// Open file
$reader->open($inputFileName);
$count = 1;
// Number of sheet in excel file
foreach ($reader->getSheetIterator() as $sheet) {
// echo "<pre>";
// Number of Rows in Excel sheet
//print_r($sheet->getRowIterator());die;
foreach ($sheet->getRowIterator() as $row) {
// It reads data after header. In the my excel sheet,
// header is in the first row.
// if ($count > 1)
{
// Data of excel sheet
if(isset($row[1]) && $row[1] != ""){
$row[1] = $row[1];
}
else{
$row[1] = 0;
}
// print_r($row);
//Here, You can insert data into database.
$conn->query("CREATE TABLE IF NOT EXISTS qrcode (id int NOT NULL PRIMARY KEY AUTO_INCREMENT, seat_no VARCHAR(10), status int DEFAULT 0,dinner_status int DEFAULT 0, date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
$conn->query("insert into qrcode (seat_no,status) values ('$row[0]','".(int)$row[1]."')");
}
$count++;
}
}
// Close excel file
$reader->close();
session_start();
$_SESSION['success']="Data imported successfully";
header('location:dashboard.php');
} else {
echo "Please Select Valid Excel File";
}
} else {
echo "Please Select Excel File";
}
?>