Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?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>


What I have tried:

I do not know that is wrong with line 6
Posted
Updated 28-Oct-18 1:02am
v2
Comments
Herman<T>.Instance 23-Oct-18 4:18am    
What error do you get?
Member 14029056 23-Oct-18 5:25am    
Notice: Only variables should be passed by reference in C:\wamp64\www\invoic4\index.php on line 6
Herman<T>.Instance 23-Oct-18 6:06am    
You call the function by value in stead of by reference. That is your problem. amd Google says:
this!! about your problem

1 solution

Where is your code?

You must change code to:
$_extension = explode(".", $_FILES["excel"]["name"]);
$extension = end($_extension);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900