i have managed to code this CSV file and it is working well..the only problem i am getting is the variable error on the form..i get this error ...Notice: Undefined variable: data in C:\xampp\htdocs\helper.php(527) : runtime-created function on line 22

how do i resolve the error? this

this my sample code...

  <form enctype="multipart/form-data" method="POST" action="" >
  CSV<input type="file" name="file" />
  <input type="submit" value="submit" name="submit"/>

  //connect to the database
  $connect = mysql_connect("localhost","root","");
  mysql_select_db("test",$connect); //select the table

  //get the csv file
  $file = $_FILES['file']['tmp_name'];
  $handle = fopen($file,"r");

  //loop through the csv file and insert into database
  do {
  if ($data[0]) {
mysql_query("INSERT INTO f38uj_zhgooglemaps_markers (title, addresstext,  published, baloon, icontype, mapid) VALUES
} while ($data = fgetcsv($handle,1000,",","'"));



Recommended Answers

All 6 Replies

You're trying to use the variable $data before it's been declared. Try doing:

while ($data = fgetcsv($handle,1000,",","'")) {

    if ($data[0]) {
        // Code here

thanks for reply
what do you mean..LOAD DATA INFILE

LOAD DATA INFILE is a MySQL function that you can use to rapidly import CSV data into a table. Look for an example on the link I provided.

Thanks for sharing the method of inserting the CVS on this site. I will try this method to insert it.

You r welcome

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.