I am importing a text file with marks for each student into my MySQL database. I am using preg_split to read each line and break the info into separate data which is working except for students with a surname containing a ['] such as O'Neil.
Error: INSERT INTO student_data (studentID,student_number, termID, course_number, course_name, storecode, grade, percent) VALUES ('13269 3100876170 Jimmy O'Neil 12 2701 MT11 MATHEMATICS 11 Q1 74 74 ','','','','','','','') 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 'Neil 12 2701 MT11 MATHEMATICS 11 Q1 74 74 ','','','','','','','')' at line 231093
The code to split the separate the file is:
ini_set("auto_detect_line_endings", true);
$file = fopen($target_file,"r");
while(! feof($file))
{
$test= fgets($file);
$array = preg_split('/\s"+/', $test);
fclose($file);
}
I am guessing that the issue is the ('/\s"+/',$test) part of the code. I have looked for clear documentation on what is going on and most of it makes sense but I couldn't find how you include all white spaces but exclude ' from being used as a delineator.