I am trying to insert data from csv file to mysql database. Data is inserted to DB. But not in the way I expected. In my case there are several text files which includes employee id, date, in time and out time. Also, I want to validate this if there is one record for the same employee number with same date it should not allow to insert the any data.
My Code
$fdate = array_filter(explode(" ", $y));
$csv->emp_id = $epf;
$a_date = date("Y-m-d", strtotime($fdate[9]));
$csv->date= $a_date;
$csv->save();
$check = "SELECT * FROM daily_attendances WHERE emp_id = $epf AND date = '$a_date'";
$sql = DB::select(DB::raw($check));
$count = count($sql);
if($count > 0){
if ($fdate[11] == "AM") {
$update_query = "UPDATE daily_attendances SET in_time = '$fdate[10]' WHERE
emp_id = $epf AND date = '$a_date'";
$sql = DB::select(DB::raw($update_query));
} elseif ($fdate[11] == "PM") {
$o_time = date("H:i:s", strtotime($fdate[10] . $fdate[11]));
$update_query = "UPDATE daily_attendances SET out_time = '$o_time' WHERE emp_id = $epf AND date = '$a_date'";
$sql = DB::select(DB::raw($update_query));
}
current output


18:18:21? It appears in neither of the two original rows.csvdata structure in file.idin this case?