<?php
$csvfilename=$_FILES['userfile']['name'];
$target_path = "c:/EasyPHP/www/eCoupoun/";
$target_path = $target_path . basename( $_FILES['userfile']['name']);
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['userfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
$skipfirstline = true;
$delimiter = ',';
include('adodb/adodb.inc.php');
$db = ADONewConnection('MySQL'); # eg. 'mysql' or 'oci8'
$db->debug = true;
$db->Connect('localhost', 'root', 'sachi', 'ecoupon');
$handle = fopen($csvfilename, "r");
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
if ($skipfirstline == true) {
$skipfirstline = false;
continue;
}
// prepare for inserting to database
foreach (array_keys($data) as $v)
$data[$v] = mysql_real_escape_string($data[$v]);
//$values = implode("','",$data);
// $values = 'sfsdaf@dfaf.com';
foreach($data as $values){
$values=implode(",",$data);
echo 'INSERT INTO couponemail(email)'.'VALUES('."$values".')';
$query= $db->Execute('INSERT INTO couponemail(email)'. 'VALUES('."$values".')'); }
die;
// $query = $db->Execute('INSERT INTO couponemail('.$values.')'. 'VALUES ('$values')');
// $query=$db->Execute('INSERT INTO couponemail VALUES($values)');
// $query = "INSERT INTO couponemail VALUES ('".$values."')";
echo "<br>".$query."<br>";
}
?>
I am getting following error please help me
The file testcsv1.csv has been uploadedINSERT INTO couponemail(email)VALUES(1,t_saigopal@yahoo.com)
(mysql): INSERT INTO couponemail(email)VALUES(1,t_saigopal@yahoo.com)
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@yahoo.com)' at line 1
adodb_mysql._execute(INSERT INTO couponemail(email)VALUES(1,t_saigopal@yahoo.com), false) % line 861, file: adodb.inc.php
adodb_mysql.execute(INSERT INTO couponemail(email)VALUES(1,t_saigopal@yahoo.com)) % line 46, file: csvindex.php
(mysql): INSERT INTO couponemail(email)VALUES(1,t_saigopal@yahoo.com)
1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@yahoo.com)' at line 1
adodb_mysql._execute(INSERT INTO couponemail(email)VALUES(1,t_saigopal@yahoo.com), false) % line 861, file: adodb.inc.php
adodb_mysql.execute(INSERT INTO couponemail(email)VALUES(1,t_saigopal@yahoo.com)) % line 46, file: csvindex.php