I have a script where I want to insert all rows in a single statement, but I don't know how to do that.
Here's the code I have so far. This only inserts one row. How can I insert multiple rows?
<?php
include ('includes/config.php');
if (strlen($_SESSION['alogin']) == 0) {
echo "<script type='text/javascript'> document.location ='adminlogin.php'; </script>";
} else {
if (isset($_POST['add'])) {
$batchname = $_POST['batchname'];
$studentid = $_POST['studentid'];
$status = $_POST['status'];
$sql = "INSERT INTO tblattendance(Date,BatchName,StudentId,Status) VALUES(CURDATE(),:batchname,:studentid,:status)";
$query = $dbh->prepare($sql);
$query->bindParam(':batchname', $batchname, PDO::PARAM_STR);
$query->bindParam(':studentid', $studentid, PDO::PARAM_STR);
$query->bindParam(':status', $status, PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
if ($lastInsertId) {
$msg = "Attendance Added successfully";
} else {
$error = "Something went wrong. Please try again";
}
}
}