mysql - Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in PHP -


mysql_connect("localhost","root",""); mysql_select_db("hitnrunf_db");  $result=mysql_query("select * jos_users outfile 'users.csv' fields escaped '""' terminated ',' enclosed '"'  lines terminated '\n' ");  header("content-type:  text/plain"); header("content-disposition: attachment; filename=your_desired_name.xls"); header("content-transfer-encoding: binary"); header("pragma: no-cache"); header("expires: 0"); print "$header\n$data"; 

in above code in query string i.e string in side mysql_quey

we getting following error

parse error: syntax error, unexpected t_constant_encapsed_string in c:\wamp\www\samples\mysql_excel\exel_outfile.php on line 8 

in query string '\n' charter not identifying string thats why above error getting

you need escape double quote as: \" instead of ""

$result=mysql_query("select * jos_users outfile 'users.csv' fields escaped '\"' terminated ',' enclosed '\"' lines terminated '\n' "); 

an un-escaped " prematurely terminate string.

example:

this incorrect: "a " double quote"
correct: "a \" double quote"


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -