Sabtu, 11 Agustus 2018

PHP CODE Import Excel File to Mysql

 <html>
    <head>
    <title>How To Import Excel (.xls) File To MySql Database Using PHP</title>
    </head>
    <body>
    <center><h1>lp2maray</h1></center>
    <form name="import_export_form" method="post" action="" enctype="multipart/form-data">
    <label>Select Excel File : </label><input type="file" name="excelfile"/><br>
    <input type="submit" name="form_submit"/>
    </form>
    </body>
    </html>


<?php
 if(isset($_POST['form_submit'])){

error_reporting(0);
require_once 'excel_reader2.php';

$filename = $_FILES['excelfile']['tmp_name'];
$data = new Spreadsheet_Excel_Reader($filename);

for ($x = 2; $x <= count($data->sheets[0]["cells"]); $x++) {
$first = $data->sheets[0]["cells"][$x][1];
$middle = $data->sheets[0]["cells"][$x][2];
$last = $data->sheets[0]["cells"][$x][3];
$sql = "INSERT INTO mytable (First,Middle,Last) VALUES ('$first','$middle','$last')";
echo $sql."\n";
//mysql_query($sql);
}
 echo"<hr>";
 echo $data->dump(true,true);
 }
?>

==========================

Download Code

Tidak ada komentar:

Posting Komentar

global_priv WARNING Selalu

 Jika muncul pesan kesalahan: Warning in .\libraries\classes\Dbal\DbiMysqli.php#209  mysqli::query(): (HY000/1034): Index for table 'glo...