我正在尝试来自http://sourceforge.net/projects/phpexcelreader/的phpexcelreaderclass,并且我一直在关注这个tut:http://rackerhacker.com/2008/11/07/importing-excel-files-into-mysql-with-php/
现在看起来一切都很顺利,但是似乎没有向数据库中插入任何东西?它回显了工作表中的数据,所以我猜它正在读取数据并将其显示回来,但它只是没有写入MySQL数据库。
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read('Export.xls');
$conn = mysql_connect("localhost","root","");
mysql_select_db("excel",$conn);
for ($x = 2; $x <= count($data->sheets[1]["cells"]); $x++) {
$rep_num = $data->sheets[1]["cells"][$x][1];
$description = $data->sheets[1]["cells"][$x][2];
$repair_type = $data->sheets[1]["cells"][$x][3];
$sql = "INSERT INTO data (`rep_num`,`description`,`repair_type`)
VALUES ('$rep_num',$description,'$repair_type')";
echo $sql."\n";
mysql_query($sql);
}我想这是很明显的事情,我确定,提前谢谢。
发布于 2012-05-09 05:37:38
试一试
$sql = "INSERT INTO data (rep_num, description, repair_type) VALUES ('$rep_num','$description','$repair_type')";确保您的字段名称正确。
发布于 2012-05-09 05:41:37
检查您的mysql_query方法结果,如下所示:
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}php.net - mysql query description
https://stackoverflow.com/questions/10506840
复制相似问题