Ds.109
Ds.109

Reputation: 730

Inserting text file into MySQL table

This is what the text file looks like ...

Adad,s,585769,M,1f1,1Ig2,S1,9834,9057, ,"AU9"," ",,AVI1ORCBTT1O1D5F,"","" Bic,Nenja,472080,M,2D,22,S2,223,90523,41924,"B016"," ",Voiol Proam Level 2,ADA2OJ2OBA,"",""

This is what my code looks like ..

$result = mysql_query("LOAD DATA LOCAL INFILE '$ptmpName' REPLACE INTO TABLE 'students' FIELDS TERMINATED BY ',' ENCLOSED BY ' ' ESCAPED BY '\\' LINES TERMINATED BY '\n'")or die ('Error: '.mysql_error ());

}

I am getting the error: "SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''students' FIELDS TERMINATED BY ',' ENCLOSED BY ' ' ESCAPED BY '\' LINES TERMINA' at line 1"

Upvotes: 0

Views: 98

Answers (1)

Marc B
Marc B

Reputation: 360842

This code is dangerous. you're allowing a user to scribble a file of their choosing ANYWHERE on your server.

Your SQL problem is here:

[...snip...] REPLACE INTO TABLE 'students' FIELDS [...snip...]
                                ^--------^---

Quoting a field/table name like that turns it into a string, not a field/table name. Either remove the quote entirely (students is NOT a reserved word, or use backticks:

... `students` ...

Upvotes: 3

Related Questions