简体   繁体   中英

Error occurs while importing excel file into MYSQL in php

I am new to php. I need to import excel details into MySQL database in php. I downloaded 2 files reader.php & oleread.php and save that under wamp/www/folder . When I execute the following code, the server throw a error like

The filename samp.xls is not readable

Give the solution to recover this problem. my code is:

<html>
  <head>
  <title>Save Excel file details to the database</title>
  </head>
  <body>
    <?php
        include 'db_connection.php';
        include 'reader.php';
        $excel = new Spreadsheet_Excel_Reader();
    ?>
        <table border="1">
        <?php
            $excel->read('samp.xls');
            $x=2;
            while($x<=$excel->sheets[0]['numRows']) {
                $id = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][1] : '';
                $name = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][2] : '';
                // Save details
                $sql_insert="INSERT INTO students (sid,name) VALUES ('$id','$name')";
                $result_insert = mysql_query($sql_insert) or die(mysql_error());
              $x++;
            }
        ?>
    </table>
  </body>
</html>

why not import it directly into phpmyadmin?? click here

The filename samp.xls is not readable

First thing to come to mind is that your php server cannot read your excel file ..

WAMP is on Windows , so Right-Click your excel file, and add read property to Everyone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM