Jump to content

[SOLVED] Inserting CSV file data into a DB


ainoy31

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.