Jump to content

[SOLVED] Handling CSV file


jeeves245

Recommended Posts

Hi guys,

 

can anyone tell me why this script isn't working? It is inserting the rows in the database, but they do not have any data in them.

 

Cheers.

 

<?php

$con = mysql_connect("localhost","root","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $con);

$file_handle = fopen("deliveries.csv", "rb");

while (!feof($file_handle) ) {

$line_of_text = fgets($file_handle);
$parts = explode(',', $line_of_text);

$sql="INSERT INTO customer (customerName, address1, address2, address3)
VALUES
('$parts[2]','$parts[6]','$parts[7]','$parts[8]')";

}

fclose($file_handle);

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
   
?>

 

Link to comment
https://forums.phpfreaks.com/topic/168576-solved-handling-csv-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.