php - How can i get the value of each column in excel and insert to MySQL -


i newbie in sql , excel can guide me this?

this full script.

<?php  include 'function/functions.php';  $excel = $_post['files'];  $upload = $_post['upload'];  $query = mysql_query("insert clients (name, age, sex, address, contact_number) values ($excel)");  if(isset($upload))  {  $query;  }  ?>  <!doctype html>  <html>  <head>  </head>  <body>  <form action="" method="post" />  upload excel file<br />  <input type="file" name="files" /><br />  <input type="submit" value="upload" name="upload" />  </form>  </body>  </html>

i'll make simple code make easy understand me,(anyway sorry bad english)

my question is, how can insert each corresponding column in excel in mysql here's picture.

enter image description here

enter image description here

use fgetcsv contents excel file array values.hope works you.

 if($_files["file"]["size"] > 0)      {        $file = fopen($filename, "r");              while (($emapdata = fgetcsv($file, 10000, ",")) !== false)              {                 $sql = "insert import(name,age,sex,address,contact_number) values('$emapdata[0]','$emapdata[1]','$emapdata[2]','$emapdata[3]','$emapdata[4]')";                 mysql_query($sql);              }              fclose($file);              echo "csv file has been imported";      }      else      echo "invalid file:please upload csv file"; 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -