May I ask questions about importing Excel files to MySQL in PHP?

Source: Internet
Author: User
Ask PHP to import an Excel file to MySQL. at last, the post was edited by ShunYea from 2013-02-0316: 23: 05 and read similar examples on the Internet. My code: & lt ;? Phprequire_once & nbsp; 'reader. php'; ask php about importing Excel files to MySQL.
At the end of this post, ShunYea edited it at 16:23:05 on and read similar online examples. it seems that all of them were changed.

My code:


Require_once 'reader. php ';

$ Data = new Spreadsheet_Excel_Reader ();
 
$ Data-> setOutputEncoding ('gbk ');

$ Data-> read('in.xls ');
@ $ Db = mysql_connect ('localhost', 'root', '123') or
Die ("cocould not connect to database .");
Mysql_query ("set names 'gbk '");
Mysql_select_db ('test1 ');
Error_reporting (E_ALL ^ E_NOTICE );


For ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++ ){
 

$ A = $ data-> sheets [0] ['cells '] [$ I] [1]; // obtain the data in the first column
$ B = $ data-> sheets [0] ['cells '] [$ I] [2]; // Obtain data in the second column
$ C = $ data-> sheets [0] ['cells '] [$ I] [3]; // Obtain data in the third column
$ D = $ data-> sheets [0] ['cells '] [$ I] [4]; // Obtain data in the fourth column
$ E = $ data-> sheets [0] ['cells '] [$ I] [5]; // Obtain data in the fifth column
$ F = $ data-> sheets [0] ['cells '] [$ I] [6]; // Obtain data in column 6
$ G = $ data-> sheets [0] ['cells '] [$ I] [7]; // obtain the data in column 7

 
$ SQL = "insert into appexp (account, appinfo, price, result, income, pay, date) VALUES ('$ A',' $ B ',' $ C ', '$ d',' $ E', '$ f',' $ G ')";
Echo $ SQL .' ';
$ Res = mysql_query ($ SQL) or die ("Error: $ SQL ");
}
?>


I will. The table is also uploaded. The in. php page is blank. what is the problem?


Thank you for your answers.
------ Solution --------------------
I am normal here, and I paste my code for your reference (my web client uploads an excel file by myself ):



Require_once 'Excel/reader. php ';

$ Data = new Spreadsheet_Excel_Reader ();

If ($ _ FILES ){

$ Check = substr ($ _ FILES ["file"] ["name"], strrpos ($ _ FILES ["file"] ["name"], ". ") + 1 );

If ($ check = "xls"
------ Solution --------------------
$ Check = "xlsx ")
{
Move_uploaded_file ($ _ FILES ["file"] ["tmp_name"], "upload/". $ _ FILES ["file"] ["name"]);
}
Else
{
Exit ('no ');
}

$ Data-> setOutputEncoding ('utf-8 ');

$ Data-> read ("upload/". $ _ FILES ["file"] ["name"]);

Error_reporting (E_ALL ^ E_NOTICE );

$ Db_host = 'localhost'; // edit_config
$ Db_user = 'root ';
$ Db_password = 'root ';
$ Db_port = 3306;
$ Db_name = 'test ';

$ Con = mysql_connect ($ db_host, $ db_user, $ db_password );
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}

$ Db_selected = mysql_select_db ($ db_name, $ con );

If (! $ Db_selected)
{
Die ("Can \'t use test_db:". mysql_error ());
}

// Delete an existing table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.