How do I insert all employee attendance(Monthly once) in mysql database Here is my db tables
att_employee_id | att_year | att_month | att_present_days | att_absent_days | att_workingdays
Date.prototype.daysInThisMonthOfThisYear=function() {
return new Date(this.getFullYear(),this.getMonth()+1,0).getDate();
}
var days_inmonth = new Date().daysInThisMonthOfThisYear();
$(document).ready(function() {
$( ".absent_days" ).keyup(function() {
var days = $(this).val();
$(this).closest("tr").find(".present_days" ).val( days_inmonth - days );
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<form name="emp_att" action="" method="post">
<table>
<thead>
<tr>
<th class="head0" style="width:5%">S.No</th>
<th class="head1" style="width:15%">Employee ID</th>
<th class="head0 no-sort" style="width:15%">No.of days present</th>
<th class="head1 no-sort" style="width:15%">No.of days absent</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>ETO0001</td>
<td><input type="text" class="present_days" name="present_days" value=""></td>
<td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>2</td>
<td>ETO0002</td>
<td><input type="text" class="present_days" name="present_days" value=""></td>
<td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>3</td>
<td>ETO0003</td>
<td><input type="text" class="present_days" name="present_days" value=""></td>
<td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
<tr>
<td>4</td>
<td>ETO0004</td>
<td><input type="text" class="present_days" name="present_days" value="" readonly></td>
<td><input type="number" name="absent_days" class="absent_days" min="0" max="<?php echo date('t'); ?>" onChange="absentdays()" style="width:100%"></td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" value="Submit">
</form>
Here is my query to get all the employees
<form name="emp_att" action="" method="post">
<table>
<thead>
<tr>
<th class="head0" style="width:5%">S.No</th>
<th class="head1" style="width:15%">Employee ID</th>
<th class="head0 no-sort" style="width:15%">No.of days present</th>
<th class="head1 no-sort" style="width:15%">No.of days absent</th>
</tr>
</thead>
<tbody>
<?php
$allemp= mysqli_query($con,"select * from t_emp e");
$all_emp = mysqli_num_rows($allemp);
if ($all_emp > 0)
{
$i=1;
while($all_emp = mysqli_fetch_assoc($allemp))
{
echo "<tr>";
echo "<td>".$i."<input type='hidden' name='serialno' value='".$i++."'></td>
<td> ".$all_emp["emp_id"]."</td>
<td><input type='text' class='present_days' name='present_days' value=''></td>";
echo "<td><input type='number' name='absent_days' class='absent_days' min='0' max= date('t') onChange='absentdays()' style='width:100%'></a></td>";
echo "</tr>";
}
}
else
{
echo "0 Results";
}
?>
</tbody>
</table>
<input type="submit" name="submit" value="Submit">
</form>
Here I am getting all the n number of employees in the above form. when entered all employees "No.of days absent" and then hit on submit I am able to send only last record to the database. Can any one help me to send all the employees attendance to database Here is my form submission query
<?php
if(isset($_POST['submit']))
{
$serialno=$_post['serialno'];
$employee_id=$_post['emp_id'];
$att_year = date('Y');
$att_month = date('m');
for($i=1; $i<= $serialno;$i++)
{
$present_days=$_POST['present_days'];
$absent_days=$_POST['absent_days'];
}
$query=mysqli_query($con,"INSERT INTO t_emp_attendance(att_employee_id,att_year,att_month,att_present_days,att_absent_days)values('$employee_id','$att_year','$att_month','$present_days','$absent_days')");
}
?>
any suggestions will be appreciated, I need to store all the employees attendance to database
</div>