php - error in importing csv file to mysql server -


this question has answer here:

i want import csv file mysql database , getting error in not able fix. please me find issue..

my code is

    <?php  if(isset($_post['submit'])) {     $connect = mysql_connect('127.0.0.1','root','');   if (!$connect) {  die('could not connect mysql: ' . mysql_error());  } $cid =mysql_select_db('ts_order_track',$connect);  $file = $_files['file']['tmp_name']; if ($_files["file"]["error"] > 0) { echo "error: " . $_files["file"]["error"] . "<br />"; }  else {   echo "hi";         $q="load data infile '$file' table tsd_orders         fields terminated ',' enclosed '"'         lines terminated '\n'          ignore 1 lines         ( order_id, customer_id, firstname, lastname, email, telephone, mobile, shipping_firstname, shipping_lastname, shipping_mobile, shipping_address_1, shipping_address_2, shipping_city, shipping_zone, shipping_postcode, shipping_country, shipping_method, payment_method, payment_code, weight, date_added, date_modified, import_order_id, sub_total, shipping_charges, tax_charges, total, order_status, courier, awb_code, coupon_amount, coupon_code, product_name, product_sku, product_model, product_quantity, product_price )";         $s=mysql_query($q, $connect );  echo "file data imported database!!";     }     mysql_close ( $connect ); } ?> 

and error is

parse error: syntax error, unexpected '' ' (t_constant_encapsed_string) in c:\xampp\htdocs\try.php

please me find error , should code here..

this csv file

order_id,customer_id,firstname,lastname,email,telephone,mobile,shipping_firstname,shipping_lastname,shipping_mobile,shipping_address_1,shipping_address_2,shipping_city,shipping_zone,shipping_postcode,shipping_country,shipping_method,payment_method,payment_code,weight,date_added,date_modified,import_order_id,sub_total,shipping_charges,tax_charges,total,order_status,courier,awb_code,coupon_amount,coupon_code,product_name,product_sku,product_model,product_quantity,product_price 3605600753,68,deepali,agni,deepali@trendspry.com,8800311993,8800311993,deepali,agni,8800311993,sushant lok,shopping arc,ggn,haryana,122001,india,free shipping,cash on delivery,cod,0.50kg,28-05-2015,28-05-2015,bhg9,1299,0,0,1299,pending,na,na,0,na,a beautiful  black , yellow georgette saree,br19891153,georgette , jacquard embroidery , printed casual , office ,1,1299 

you need escape newline character \n and double quotation " in query:

$q="load data infile '$file' table tsd_orders     fields terminated ',' optionally enclosed '\"'     lines terminated '\\n'      ignore 1 lines     ... 

have @ this post syntactically-correct way use load data inside php script.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -