将excel文件上传到phpmysql错误 [英] Upload excel file to phpmysql error
本文介绍了将excel文件上传到phpmysql错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我要上传我的excel到sql但是我上传的时候我得到了这个错误
注意:只有变量应该通过引用传递给C:\ wamp64 \ www.h第6行的invoic4 \ index.php
这是index.php文件
Hello guys I am going to upload my excel to sql but while i upload i get this error
Notice: Only variables should be passed by reference in C:\wamp64\www\invoic4\index.php on line 6
and this is index.php file
<?php
$connect = mysqli_connect("localhost", "root", "", "invoice4");
$output = '';
if(isset($_POST["import"]))
{
$extension = end(explode(".", $_FILES["excel"]["name"])); // 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("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
$output .= "Data Inserted<br>";
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for($row=2; $row<=$highestRow; $row++)
{
$output .= "";
$docno = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(0, $row)->getValue());
$importaction = mysqli_real_escape_string($connect, $worksheet->getCellByColumnAndRow(1, $row)->getValue());
$query = "INSERT INTO invoice_table(docno, importaction) VALUES ('".$docno."', '".$importaction."')";
mysqli_query($connect, $query);
$output .= '';
$output .= '';
$output .= '';
}
}
$output .= '<table class="table table-bordered"><tbody><tr><td>'.$docno.'</td><td>'.$importaction.'</td></tr></tbody></table>';
}
else
{
$output = 'Invalid File'; //if non excel file then
}
}
?>
<title>Import Excel to Mysql using PHPExcel in PHP
body
{
margin:0;
padding:0;
background-color:#f1f1f1;
}
.box
{
width:1100px;
border:1px solid #ccc;
background-color:#fff;
border-radius:5px;
margin-top:100px;
}
<div class="container box">
<h3 align="center">Import Excel to Mysql using PHPExcel in PHP</h3><br>
Select Excel File
<br>
<br>
<br>
<?php
echo $output;
?>
</div>
什么我试过了:
我不知道第6行是错的
What I have tried:
I do not know that is wrong with line 6
推荐答案
connect = mysqli_connect( localhost, root, , invoice4);
connect = mysqli_connect("localhost", "root", "", "invoice4");
output = ' '跨度>;
if(isset(
output = ''; if(isset(
_POST [ import]))
{
_POST["import"])) {
这篇关于将excel文件上传到phpmysql错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文