mysqli insert语句不适用于phpexcel
我正在尝试通过网页将excel 2007文件中的数据插入mysql。我正在使用phpexcel库,但它无法工作..请提供帮助..我的代码如下所示: 我已经检查了每个地方,大多数代码都是这样的;我的数据库仍然是空的mysqli insert语句不适用于phpexcel,php,mysqli,Php,Mysqli,我正在尝试通过网页将excel 2007文件中的数据插入mysql。我正在使用phpexcel库,但它无法工作..请提供帮助..我的代码如下所示: 我已经检查了每个地方,大多数代码都是这样的;我的数据库仍然是空的 <?php //In case you want the script to be executed at a predefined time interval, use this /*header('Refresh: 30'); */ //Establishing
<?php
//In case you want the script to be executed at a predefined time interval, use this
/*header('Refresh: 30'); */
//Establishing connection to Mysql Database:
$mysqli = new mysqli("localhost", "root","","final");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit(); }
//PHPEXCEL Reader
require 'includes/PHPExcel.php';
require_once 'includes/PHPExcel/IOFactory.php';
//action that happens when the button is pressed
if (isset($_POST['button1']))
{
echo "button on is pressed";
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] .
"You have not selected a file or some other error <br />";
}
else
{ // Errorless start
$inputFileName=$_FILES["file"]["name"];
$objPHPExcel = PHPExcel_IOFactory::load("C:/julisha/uploads/".$inputFileName);
// Creating a temporary copy on the server
$location="C:/wamp/www/julisha/uploads/"; // write the location on
// server where a copy should be created
move_uploaded_file($_FILES["file"]["tmp_name"],
$location . $_FILES["file"]["name"]);
//$inputFileName = $file_name;
$inputFileType = 'Excel2007';
$objReader = PHPExcel_IOFactory::createReader("$inputFileType");
$objReader->setReadDataOnly(true);
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
//Display Excel data on webpage
echo '<table>' . "\n";
for ($row = 1; $row <= $highestRow; ++$row) {
echo '<tr>' . "\n";
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
echo '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>' . "\n";
}
echo '</tr>' . "\n";
}
echo '</table>' . "\n";
//Preparing to import data from Excel to Mysql Database:
for($row = 2; $row <= $highestRow; ++$row) {
for($col = 0; $col < $highestColumnIndex; ++$col) {
$rows[$col] = $objWorksheet->getCellByColumnAndRow($col, $row);
}
$mysqli->query("INSERT INTO temp_results (Adm_No,Engl,Kis,Math,Chem) VALUES ('$rows[0]', '$rows[1]', '$rows[2]', '$rows[3]', '$rows[4]',)");
}
}
}
$mysqli->close();
?>
您的查询末尾有一个,
,请将其删除
改变
$mysqli->query("INSERT INTO temp_results (Adm_No,Engl,Kis,Math,Chem) VALUES ('$rows[0]', '$rows[1]', '$rows[2]', '$rows[3]', '$rows[4]',)");
与
$mysqli->query("INSERT INTO temp_results (Adm_No,Engl,Kis,Math,Chem) VALUES ('$rows[0]', '$rows[1]', '$rows[2]', '$rows[3]', '$rows[4]')");