I have been following a csv import tutorial with PHP using mysql to store data, when I echo the data, I am getting the whole row instead of getting the data in the first cell. Could this be an issue with my csv file because my field delimited is: comma and my text delimited is: double quotes? when I echo out the first element echo $fileop[0];
, I get the whole row instead of getting the first element which should be: title.
Anyone would know what is the issue?
Here is my code:
<?php
$host = 'localhost';
$user = 'root';
$pass = 'root';
$db_name = 'testcsvdump';
$db = new mysqli($host, $user, $pass, $db_name);
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
if( isset($_POST['submit']) ){
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
while ( ($fileop = fgetcsv($handle, 1000, ',')) !== false ) {
echo $fileop[0];
}
}else{
echo 'failed';
}
?>
and the output is:
titleNameEmail Address
(but I am trying to echo out "title" which is the first element in the first cell). And when I open my CSV file, each title and data are in their own cell. I used the following settings to export the file.
Field delimited is: comma
Text delimited is: double quotes