I got in some dead-end. I have csv file, delimited by commas, but I'm not able to import data to database. What can be causing this? No errors, simpy no data getting imported
Import code:
<form enctype="multipart/form-data" method="POST">
<input name="csv" type="file">
<input type="submit" name="submit" value="submit">
</form>
<?php
if (isset($_POST['submit'])) {
$i=0;
require "connection.php";
if (is_uploaded_file($_FILES['csv']['tmp_name'])) {
echo "<h3>" . "File ". $_FILES['csv']['name'] ." uploaded successfully." . "</h3>";
}
$handle = fopen($_FILES['csv']['tmp_name'], "r");
$import=$db->prepare("INSERT INTO adherence(
dateandtime,
lastname,
firstname,
paidtime,
approvedtime,
notadhering)VALUES(
?,?,?,?,?,?)");
while (($data = fgetcsv($handle, 10000,',')) !== FALSE) {
if($i>0) {
$data = str_replace('"', '', $data);
$myDate = date("Y/m/d",strtotime(str_replace('/','-',$data[0])));
$import->bindParam(1, $myDate, PDO::PARAM_STR);
$import->bindParam(2, $data[1], PDO::PARAM_STR);
$import->bindParam(3, $data[2], PDO::PARAM_STR);
$import->bindParam(4, $data[3], PDO::PARAM_STR);
$import->bindParam(5, $data[4], PDO::PARAM_STR);
$import->bindParam(6, $data[5], PDO::PARAM_STR);
$import->execute();
}
$i++;
}
$removal=$db->prepare("delete FROM adherence WHERE approvedtime = '0' OR notadhering IS NULL");
$removal->execute();
fclose($handle);
}
Any help would be appreciated.