Answer the question
In order to leave comments, you need to log in
How to write the path in PHPExcel correctly?
Good day, there is a code for importing data from excel to the mysql database, when I immediately write the name of the excel file itself, then the import occurs without errors, and if I start specifying the path through the file selection (input = "file"), it gives an error.
<form class="" action="" method="post">
<input type="file" name="file_path" value="">
<button type="submit" name='import_b'>Импортировать</button>
</form>
<?php
if (isset($_POST['import_b'])) {
include "Classes/PHPExcel/IOFactory.php";
$file_path = $_FILES['file_path']['tmp_name'];
$objPHPExcel = PHPExcel_IOFactory::load($file_path);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for ($row = 2; $row <= $highestRow; ++ $row)
{
$name = $worksheet->getCellByColumnAndRow(0, $row);
$name_noSpace = $worksheet->getCellByColumnAndRow(0, $row);
$nameScore = $worksheet->getCellByColumnAndRow(1, $row);
$no_str_name = str_replace(' ','',$name_noSpace);
$result_set = mysqli_query($connect, "SELECT `name`, `nameScore` FROM `test_excel` WHERE `name` = '$name' AND `nameScore` = '$nameScore' ");
$present_in = mysqli_fetch_row($result_set);
if(isset($present_in["0"]) && $nameScore == $present_in['1']){
echo "";
}
else{
$result = mysqli_query($connect, "INSERT INTO `test_excel`(name, nameScore, noSpaceName) VALUES ('$name', '$nameScore', '$no_str_name')") or die('Ошибка чтения записи:'.mysqli_error());
}
}
}
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question