An error occurred while importing an excel file online ..
Error_reporting (0 );
// Import a CSV file
$ Connect = mysql_connect ("localhost", "root", "root") or die ("cocould not connect to database ");
Mysql_select_db ("student", $ connect) or die (mysql_error ());
Mysql_query ("SET character_set_connection = utf8, character_set_results = utf8, character_set_client = binary", $ connect );
$ Fname = $ _ FILES ['myfile'] ['name'];
$ Handle = fopen ("$ fname", "r ");
While ($ data = fgetcsv ($ handle, 10000 ,","))
{
$ Q = "insert into timetable (cid, week, jieci, name, teacher) values ('$ data [0]', '$ data [1]', '$ data [2]', '$ data [3]', '$ data [4]') ";
Mysql_query ($ q) or die (mysql_error ());
}
Fclose ($ handle );
$ Fname = $ _ FILES ['myfile'] ['name'];
$ Do = copy ($ _ FILES ['myfile'] ['tmp _ name'], $ fname );
If ($ do)
{
Echo "data imported successfully
";
} Else {
Echo "";
}
Import
Excel will be under the folder, but there is no
When I continue to submit, the message "You have an error in your SQL syntax" is displayed; check the manual that corresponds to your MySQL server version for the right syntax to use near '\ x87. \ xC76 \ x90 \ xF4 \ x03 \ x14kl \ x8B \ xD8 \ x92 \ xD0L \ xD2 \ xE4 \ xEF; v \ x16J \ xC8 \ x82i \ xA0 \ xB 'at line 1
What should I do? I have to submit my homework tomorrow for guidance.
Reply to discussion (solution)
Echo $ q; paste the result to see
"\ X87. \ xC76 \ x90 \ xF4 \ x03 \ x14kl \ x8B \ xD8 \ x92 \ xD0L \ xD2 \ xE4 \ xEF; v \ x16J \ xC8 \ x82i \ xA0 \ xB"
Apparently not UTF-8 encoded data
Save the csv file as a UTF-8-encoded document.