0

I am trying to insert CSV file data into my database table using php . But my CSV 2 column data is storing in same column in database .

here is my database

database

here is my CSV data

csv data

Here is my PHP code

?php
if(isset($_POST["submit"]))
{
  $file = $_FILES['file']['tmp_name'];
  $handle = fopen($file, "r");
  $c = 0;
  while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
  {
    $name = $filesop[0];
    $project = $filesop[1];

    $sql = mysql_query("INSERT INTO mytask (name, project) VALUES ('$name','$project')");
    $c = $c + 1;
  }

  if($sql){
  echo "You database has imported successfully. You have inserted ". $c ."recoreds";
  }else{
  echo "Sorry! There is some problem.";
  }

    }
 ?>

code refereed by refrence

any help ..?

Trend Snaps
  • 198
  • 4
  • 15
  • 1
    Possible duplicate of [SQL table with "list" entry vs SQL table with a row for each entry](http://stackoverflow.com/questions/41215624/sql-table-with-list-entry-vs-sql-table-with-a-row-for-each-entry) – e4c5 Dec 20 '16 at 07:13

1 Answers1

1

try to give a value with comma seperated in CSV file .

example

coloumn1 name,project

mani
  • 436
  • 3
  • 13