Reputation: 372
What is wrong with this code. Why not the character data from the array is being imported to the sql table. My excel sheet contains mixture of character and integers which I have to import. I replaced every characters to some integer value in my excel sheet and checked and then I found that It is working fine but if it contains characters(alphabets) then it does not work. In the table also the column data-types are fine as they are Varchar.
I do not know why it is not able to import characters. If anyone has any clue or solution please reply back.
See this at Pastebin here: http://pastebin.com/q2KcUZBJ
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once 'excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("sample.xls");
$con = mysql_connect("localhost","root","root");
mysql_select_db("databaseName", $con);
$a=array("1"=>($data->val(1,'A')),"2"=>($data->val(1,'B')),"3"=>($data->val(1,'C')),"4"=> ($data->val(1,'D')),"5"=>($data->val(1,'E')),"6"=>($data->val(1,'F')),"7"=>($data->val(1,'G')));
$import="INSERT INTO tablename (col1, col2, col3, col4, col5, col6,col7) VALUES ($a[1],$a[2],$a[3],$a[4],$a[5],$a[6],$a[7])";
mysql_query($import) or die("mysql_error()");
?>
Upvotes: 0
Views: 423
Reputation: 212412
Because character (string) values must be quoted in your SQL Insert statement.
Updating to MySQLi or PDO where you can use prepared statements would resolve this issue, and remove your dependency on a deprecated MySQL interface
Upvotes: 1