ainoy31 Posted September 11, 2007 Share Posted September 11, 2007 Hello- I have a csv file that gets uploaded and the data is suppose to insert into a DB. I am abe to upload the csv file but it just hangs when trying to insert into the DB. I have tried going over my code many times and can not figure it out. Here is my code: $target_dir = "."; $target_path = $target_dir . $filename; //check to see if the file already exist in the folder if(!file_exists($target_path)) { //moving the uploaded file to a new place if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target_path)) { $handle = fopen($filename, "r"); //begin looping through the lines while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { //setup the mysql query $import="INSERT INTO carriers_schedule (s_ID, s_deptport, s_destport, s_startdate, carrier_email, carrier_name, carrier_phone) VALUES ('', '$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]')"; mysql_query($import) or die(mysql_error()); }//end of WHILE //close the file fclose($handle); Any suggestion would be much appreciated. TY Link to comment https://forums.phpfreaks.com/topic/68868-solved-inserting-csv-file-data-into-a-db/ Share on other sites More sharing options...
Jessica Posted September 11, 2007 Share Posted September 11, 2007 What I usually do in this sort of thing is print out each time it inserts one, so I can see if it's working while it loads. IE, add this: print $import.'<br />'; above this line mysql_query($import) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/68868-solved-inserting-csv-file-data-into-a-db/#findComment-346123 Share on other sites More sharing options...
ainoy31 Posted September 11, 2007 Author Share Posted September 11, 2007 i realize that i am uploading the csv file in the same directory as my script to isnert into the DB so i did not have to declare a target path. all is working well now. ty Link to comment https://forums.phpfreaks.com/topic/68868-solved-inserting-csv-file-data-into-a-db/#findComment-346163 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.