I'm trying to import and fetch data from CSV file and store it in my database
my database table schema is like this
users ( ID , Fname , Lname, user_type , major , Bday , Email,password , image , status )
csv ( 111 , Leo , pichon, , business, , leo@yzu.cn )
and this is my csv file schema , columns only matching the required filed of my database schema its somthing like this :
'' the empty filed either have default value or null ''
after importing i get the following notice for almost each row of my data file : Undefined offset: 1 in php csv here's my php function :
if ($_GET['action'] = 'UsersCvs') {
if (isset($_FILES['users_cvs']['name'])) {
$file = $_FILES['users_cvs']['tmp_name'];
if ($_FILES["users_cvs"]["size"] > 0) {
$handle = fopen($file, "r");
$c = 0;
while (($files = fgetcsv($handle, 2000, ",")) !== false) {
// $id = mysqli_real_escape_string($link , $files[0]);
// $fname = $files[1];
// $lname = $files[2];
// $user_type = $files[3];
// $major = $files[4];
// $email = $files[6];
// $gender = mysqli_real_escape_string($link, $filesop[6]);
//$sql = "INSERT INTO users(ID , Fname,Lname , user_type , major , Email) values ('" . $id . "','" . $fname . "' ,'" . $lname . "' ,'" .$user_type. "','" . $major . "','" . $email . "')";
// mysqli_query($link, $sql);
$num = count($files);
echo "<p> $num fields in row $c: <br /></p>\n";
$c++;
for ($i = 0; $i < $num; $i++) {
echo $files[$i] . "<br />\n";
}
}
fclose($file);
// if ($sql) {
// echo 1 ;
// } else {
// echo mysqli_error($link); ;
// }
} else {
}
}else{
echo 'no file found';
}
}
what seems strange to my and after inspection my data gets encoded to unreadable string somthing like this
<p> 3 fields in line 2: <br /></p>
�Ѷѩ\h�1�������
��drK
K(G~�S⼥���Nw|x���
�s�k�Ŗ�X���J�fb�fWш�eʬ�y�`hc�g�
1 fields in line 3:
2 fields in line 4:
I've really tried my best and did online research but i couldn't find any matching reference i would highly appreciate help thanks in advance