0

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"/>
  </form>

  //connect to the database
  $connect = mysql_connect("localhost","root","");
  mysql_select_db("test",$connect); //select the table
  if(isset($_POST['submit']))
  {

  //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
    (
       '".addslashes($data[0])."',
       '".addslashes($data[1])."',
       '".addslashes($data[2])."',
       '".addslashes($data[3])."',
       '".addslashes($data[4])."',
       '".addslashes($data[5])."'
     )
  ");
 }
} while ($data = fgetcsv($handle,1000,",","'"));

}

?>
3
Contributors
6
Replies
22
Views
3 Years
Discussion Span
Last Post by eddstyson
0

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
    }
}
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.