I know my question answer available on stackoverflow. but i need solution using mysqli_query Function to insert multi rows in table attendance. I have codes oop class function to fetchdata to display all Records from table. i designed one dropdown with options present and absent with this form. when all records display from table a dropdown list display in last colmn of html for tick employee absent or present.
Form Fields Staff_id Staff_name attendance
This is my HTML Form Codes
<form action="atup.php" method="post" >
<table class="table-bordered table mt-3">
<thead>
<tr>
<th>#</th>
<th>Staff ID</th>
<th>Employee Name</th>
<th>Department</th>
<th>Desgignation</th>
<th>Action</th>
</tr>
</thead>
<tbody >
<?php
$fetchdata=new DB_con();
$sql=$fetchdata->fetchdata();
$cnt=1;
while($row=mysqli_fetch_array($sql))
{
?>
<tr>
<td><?php echo htmlentities($cnt);?></td>
<td><input type="text" disabled name="sname" value="<?php echo htmlentities($row['id']);?>" ></td>
<td><input type="text" disabled name="sname" value="<?php echo htmlentities($row['name']);?>"></td>
<td><input type="text" disabled name="dept" value="<?php echo htmlentities($row['dept']);?>"></td>
<td><input type="text" disabled name="desi" value="<?php echo htmlentities($row['desi']);?>"></td>
<td>
<select name="att" class="form-control" required="" id="">
<option value="">Select Option</option>
<option value="Present">Present</option>
<option value="Absent">Absent</option>
</select>
</td>
</tr>
<?php
// for serial number increment
$cnt++;
} ?>
<tr>
<td class="text-right" colspan="6" >
<input type="hidden" name="action" value="add_attendance">
<input type="hidden" data-provide="datepicker" data-date-end-date="0d" name="attendance_date" value="19-May-2022">
<input type="submit" value="Submit" class="btn btn-primary">
</td>
</tr>
</tbody>
</table>
</form>
// include database connection file
include_once("functions.php");
//Object
$updatedata=new DB_con();
if(isset($_POST['submit']))
{
// Posted Values
//$sname=$_POST['sname'];
for ($i = 0; $i < count($_POST['sname']); $i++) {
$sname = $_POST['sname'][$i];
print_r($sname);
}
//Function Calling
$sql=$updatedata->insertatt($sname);
// Mesage after updation
echo "<script>alert('Record Inserted successfully');</script>";
// Code for redirection
echo "<script>window.location.href='allstaff.php'</script>";
}
my php file atup.php codes