gpt4 book ai didi

PHPExcelReader 无法写入数据库

转载 作者:行者123 更新时间:2023-11-29 03:09:28 26 4
gpt4 key购买 nike

我正在使用来自 http://sourceforge.net/projects/phpexcelreader/ 的 phpexcelreaderclass我一直在关注这个图: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);
}

我想这很明显,我敢肯定,在此先感谢。

最佳答案

尝试

$sql = "INSERT INTO data (rep_num, description, repair_type) VALUES ('$rep_num','$description','$repair_type')";

确保您的字段名称正确。

关于PHPExcelReader 无法写入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10506840/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com