How to Insert data into table from excel file in php

Sangwan Pankaj Reply 00:29

How to Insert data into table from excel file in php


Step 1:- Open an excel file and save as "Excel Data" text file and in below sample code, "test.txt" is excel-data excel file.

Step 2:- Now, follow the below instruction for create code for insert data into table in mysql using php.


<?php
  include 'config.php';
// Connect to your database.

$fp = fopen("test.txt", "r");    // Open that file('Excel Data') for reading

while($line = fgets($fp))      // Loop through each line
{

     list ($name, $first) = explode("\t", $line);

     // Split the line by the Excel Data and store it in our list...

     $sql = "insert into user (name,phone) values ('$name', '$first')";

     // Generate sql string...

     mysql_query($sql) or die ( mysql_error() );        // Execute the sql

}

?>

Step 3:- Run file.

Related Posts

xampp 6977526040992695105
Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us