0

Trying to load a CSV into a MySQL database. Can't get it to work...

SQL Query =

$query = "LOAD DATA LOCAL INFILE `$ptempName` INTO TABLE `students` FIELDS TERMINATED BY ','  LINES TERMINATED BY '\r' ESCAPED BY ',' ENCLOSED BY '" . '"' . "   ('StudentNumber', 'FirstName', 'LastName' , 'Gender' , 'Year', 'Email', 'DOB', 'Phone', 'Notifications');";
$result = mysql_query($query)or die ('Error: '.mysql_error ());

Error: 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 '` INTO TABLEstudents` FIELDS TERMINATED BY ',' LINES TERMINATED BY ' ' ESCAP' at line 1

1 Answer 1

2

Backticks are used to escape database, table and column names only.

For strings you can usually use single or double quotes, as in '$ptempName'.

Be absolutely sure you have properly escaped this value if you are getting it from a user. When using mysql_query you are playing with fire.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.