Reputation: 3993
Im having a go with the phpexcelreaderclass from http://sourceforge.net/projects/phpexcelreader/ and I have been following this tut: http://rackerhacker.com/2008/11/07/importing-excel-files-into-mysql-with-php/
Now all seems to be going well but it dosn't seem to insert anything into the database? It echo's back to me the data from the sheet, so I guess its reading it and displaying it back but its just not writing to the MySQL database.
<?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);
}
I guess its something obvious I'm sure, thanks in advance.
Upvotes: 2
Views: 297
Reputation: 1
Check your mysql_query method result like this:
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
php.net - mysql query description
Upvotes: 0
Reputation: 6512
try
$sql = "INSERT INTO data (rep_num, description, repair_type) VALUES ('$rep_num','$description','$repair_type')";
make sure your field names are correct.
Upvotes: 1