Php submits excel data to mysql

Source: Internet
Author: User
Php submits excel data to mysql for example. if The computer is installed with WIN7, an error occurs: The filename C: \ Windows \ Temp \ phpEA26.tmp is not readable.
You can also provide a piece of inserted code.


Reply to discussion (solution)

Insufficient permissions?
Specify upload_tmp_dir in php. ini to the appropriate directory.

The code for inserting MYSQL is as follows:
Error_reporting (E_ALL ^ E_NOTICE );
Require_once 'Conn. php ';
Mysql_query ("set names 'gbk '");

If ($ _ POST ){
$ Import_TmpFile = $ _ FILES ['file'] ['tmp _ name'];
Require_once 'Excel/reader. php ';
$ Data = new Spreadsheet_Excel_Reader ();
$ Data-> setOutputEncoding ('gbk ');
$ Data-> read ($ Import_TmpFile );
$ Array = array ();

For ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++ ){
For ($ j = 1; $ j <= $ data-> sheets [0] ['numcols']; $ j ++ ){
$ Array [$ I] [$ j] = $ data-> sheets [0] ['cells '] [$ I] [$ j];
}
}
Sava_data ($ array );

}

Function sava_data ($ array ){
$ Count = 0;
$ Total = 0;
Foreach ($ array as $ tmp ){
$ Isql = "Select t_id from test where t_id = '". $ tmp [1]. "'";
$ SQL = "Insert into test (t_title, t_date) value (";
$ SQL. = "'". $ tmp [1]. "', '". $ tmp [2]. "')";


If (! Mysql_num_rows (mysql_query ($ Isql ))){
If (mysql_query ($ SQL )){
$ Count ++;
}
}
$ Total ++;
}
Echo "script" alert ('total ". $ total. "Data entries, import ". $ count. "Data entries succeeded"); location = 'exceld. php'; script ";

}


Function ttodd ($ text ){
$ Jd1900 = GregorianToJD (1, 1, 1900)-2;
$ MyJd = $ text + $ jd1900;
$ MyDate = JDToGregorian ($ myJd );
$ MyDate = explode ('/', $ myDate );
$ MyDateStr = str_pad ($ myDate [2], 4, '0', STR_PAD_LEFT ). "-". str_pad ($ myDate [0], 2, '0', STR_PAD_LEFT ). "-". str_pad ($ myDate [1], 2, '0', STR_PAD_LEFT );
Return $ myDateStr;
}
?>

No error occurs, but data cannot be inserted. why ??

Directly spell out SQL statements

Debug the program step by step to see where it is going

If (! Mysql_num_rows (mysql_query ($ Isql ))){
If (mysql_query ($ SQL) {// if you enter here, you can use echo mysql_error (); to find out what is wrong
$ Count ++;
}

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.