In my page there are 2 values which is employee id and type, inside type in and out is there. if student select in so value inserted in in time in mysql and if student select out so value inserted in out time column. But in my case not this happended. In time only inserted for student id 1 after that whenever i select in time for any student it will goes in else part and show me already added. Out time updated for everyone but in time is not inserted for everyone so help me for this.
<?php
session_start();
$branch=$_SESSION['branch'];
include('../dist/includes/dbcon.php');
$emp_id = $_POST['emp_id'];
$type = $_POST['type'];
//echo $type;
$query2=mysqli_query($con,"select in_time,emp_id from emp_a")or die(mysqli_error($con));
//$count=mysqli_num_rows($query2);
while($row=mysqli_fetch_array($query2))
{
$in = $row['in_time'];
$id = $row['emp_id'];
}
//echo $in;
if($type == 'In' && is_null($in))
{
mysqli_query($con,"INSERT INTO emp_a(emp_id,att_date,in_time,status) VALUES('$emp_id',curdate(),now(),1)")or die(mysqli_error($con));
echo "<script type='text/javascript'>alert('Successfully added time log!');</script>";
}
elseif($type == 'Out')
{
mysqli_query($con,"update emp_a set out_time = now(),status = 1 where emp_id = '$emp_id' and att_date=curdate()")or die(mysqli_error($con));
echo "<script type='text/javascript'>alert('Leaving Time added!');</script>";
}
else
{
echo "<script type='text/javascript'>alert('No!');</script>";
}
echo "<script>document.location='home.php'</script>";
?>
You need to pass $emp_id
in order to get in_time
, out_time
for perticular employee, currently it gives in and out time for all the employees and get the last employee detail from the while loop.
$query2=mysqli_query($con,"select in_time,emp_id from emp_a where emp_id='$emp_id'")or die(mysqli_error($con));
//$count=mysqli_num_rows($query2);
while($row=mysqli_fetch_array($query2))
{
$in = $row['in_time'];
$id = $row['emp_id'];
}