Can someone give a helping hand on an error from this code
I am trying to send this array of values to the data base, I used Simplexlsx to parse the xlsx file, it was working and it stopped working when all of a sudden.
This is the array of data i am trying to insert to DB.
Array
(
[ac_no] => 1
[no] =>
[name] => Williams Isaac
[date_time] => 7/12/2016
[onduty] =>
[offduty] =>
[clock_in] => 04:26:00
[clock_out] => 17:00:20
[work_time] => 10:36:04
[before_ot] =>
[ndays_ot] =>
[weekend_ot] => 10:36:04
[holiday_ot] =>
[total_ot] =>
[memo] => 10:36:04
)
Array
(
[ac_no] => 6
[no] =>
[name] => Williams Bode
[date_time] => 7/12/2016
[onduty] =>
[offduty] =>
[clock_in] => 04:26:00
[clock_out] => 14:23:42
[work_time] => 09:57:42
[before_ot] =>
[ndays_ot] =>
[weekend_ot] => 09:57:42
[holiday_ot] =>
[total_ot] =>
[memo] => 09:57:42
)
Below is the code to insert to db
<?php
include 'simplexlsx.class.php';
include 'models/database.php';
$xlsx = new SimpleXLSX('attreport.xlsx');
echo '<h1>';
echo date("Y");
echo '</h1>' ;
list($num_cols, $num_rows) = $xlsx->dimension();
$f = 0;
$data = array();
foreach( $xlsx->rows() as $r )
{
// Ignore the inital name row of excel file
if ($f == 0)
{
$f++;
continue;
}
for( $i=0; $i < $num_cols; $i++ )
{
if ($i == 0) $data['ac_no'] = $r[$i];
else if ($i == 1) $data['no'] = $r[$i];
else if ($i == 2) $data['name'] = $r[$i];
else if ($i == 3) $data['date_time'] = $r[$i];
else if ($i == 4) $data['onduty'] = $r[$i];
else if ($i == 5) $data['offduty'] = $r[$i];
else if ($i == 6) $data['clock_in'] = $r[$i];
else if ($i == 7) $data['clock_out'] = $r[$i];
else if ($i == 8) $data['work_time'] = $r[$i];
else if ($i == 9) $data['before_ot'] = $r[$i];
else if ($i == 10) $data['ndays_ot'] = $r[$i];
else if ($i == 11) $data['weekend_ot'] = $r[$i];
else if ($i == 12) $data['holiday_ot'] = $r[$i];
else if ($i == 13) $data['total_ot'] = $r[$i];
else if ($i == 14) $data['memo'] = $r[$i];
}
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO `attendance` (`ac_no`, `no`, `name`, `date_time`, `onduty`, `offduty`, `clock_in`, `clock_out`, `work_time`, `before_ot`, `ndays_ot`, `weekend_ot`, `holiday_ot`, `total_ot`, `memo`) VALUES (:ac_no, :no, :name, :date_time, :onduty, :offduty, :clock_in, :clock_out, :work_time, :before_ot, :ndays:ot, :weekend_ot, :holiday_ot, :total_ot, :memo)";
$q = $pdo->prepare($sql);
$q->execute(array_values($data));
echo '<pre>';
print_r($data);
echo '</pre>' ;
}
?>
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\Payroll\excel.php:49 Stack trace: #0 C:\xampp\htdocs\Payroll\excel.php(49): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\Payroll\excel.php on line 49
Then i get this error when i run the script