I've a multidimensional array to insert into mysql table. Trying to add datetime time along with other elements in that array. but everytime i get this error. :
Notice: Undefined offset: 10 in C:\xampp\htdocs\Auto-attendance\main\proccess_attendance.php on line 47
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'att_status' cannot be null' in C:\xampp\htdocs\Auto-attendance\main\proccess_attendance.php:60 Stack trace: #0 C:\xampp\htdocs\Auto-attendance\main\proccess_attendance.php(60): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\Auto-attendance\main\proccess_attendance.php on line 60
I don't get where is the prob.
<?php
require_once("db_const.php");
if (!$_SERVER['REQUEST_METHOD']=='POST'
|| !$_POST['submit']=='save'
|| empty($_POST['subject_name'])
|| empty($_POST['subject_code'])
|| empty($_POST['department_name'])
|| empty($_POST['department_short_name'])
|| empty($_POST['teacher_name'])
|| empty($_POST['date'])
|| empty($_POST['time'])
|| empty($_POST['student'])
|| empty($_POST['stroll'])
|| empty($_POST['status'])
) {
header('Location: ../student_attendance.php?page=take-attendance');
} else {
## connect mysql server
/** $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} :
{$mysqli->connect_error}</p>";
exit();
}**/
## query database
# prepare data for insertion 538 072 662 2716
$subject_name = $_POST['subject_name'];
$subject_code = $_POST['subject_code'];
$department_name = $_POST['department_name'];
$department_short_name = $_POST['department_short_name'];
$teacher_name = $_POST['teacher_name'];
$date = $_POST['date'];
$time = $_POST['time'];
$student = $_POST['student'];
$student_roll = $_POST['stroll'];
$status = $_POST['status'];
$date=date_create_from_format("j-M-Y", $date);
$date= date_format($date,"Y-m-d");
$timestamp = date('Y-m-d H:i:s');
foreach($student as $k=>$v){
$st[] = array($subject_name, $subject_code, $department_name,
$department_short_name, $teacher_name, $date, $time, $timestamp, $v,
$student_roll[$k], $status[$k]); }
$db = new PDO('mysql:host=localhost;dbname=auto_attendance', 'root',
'');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$insert = $db->prepare(
'INSERT INTO student_attendance (subject_name , subject_code,
department_name, department_short_name,
teacher_name, date, time, timestamp, student_name, student_roll,
att_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
foreach($st as $values) {
$result = $insert->execute($values);
}
if($result == true) {
echo "<script>alert('Record successfuly
Saved.');window.location.href='../student_attendance.php?page=take-
attendance';</script>";
}
else {
echo "<script>alert('Record couldnt be
Saved.');window.location.href='../student_attendance.php?page=take-
attendance';</script>";
}
}
?>