Sorry for the confusion, if any!
Basically, I am trying to write a basic clocking in machine that is completely automated i.e. employees only need to scan their id card and they will either be clocked in or out.
The easy part was finding out if the employee was clocked in or out, however it is not quite as simple as that, employees will have breaks.
What I am trying to do is scan the employee id card and check to see if the time is greater than for instance 12:00pm if it is then place that time in the right field in mysql.
I have come very very close although what I have will insert the current time in all mysql fields above the time set by myself i.e. scan barcode at 12:00pm and fields for times 12:00, 14:00 and 17:00 will have the time and date inserted into it.
Any thoughts? Is it Possible?
Thanks in advance
Can you show us more code? It sounds like you’re checking if the time is greater than 12:00pm, when you should be checking if it’s…
- greater than 12:00 and less than 14:00, or
- greater than 14:00 and less than 17:00, or
- greater than 17:00
…but it’s hard to tell without seeing code.
This is what I have, being a novice it’s not too brilliant but sort of works
if (date(‘H:i’) > 11){
$sendquery = “UPDATE emptime SET lunch_out='” . date(‘o-m-d H:i’) . “’ WHERE badge_number='” . $_POST[‘employee’] . “'”;
$sendresult = mysql_query($sendquery);
}
So then it looks like that’s the problem (I don’t know where the 11 came from, though; timezone difference?). You’ll have to set up a much more comprehensive check to make sure you’re updating the right time:
$now = date('H:i');
$sql = 'UPDATE emptime SET ';
if (11 < $now && $now <= 13) {
$sql .= 'lunch_out';
} else if (13 < $now && $now <= 16) {
$sql .= 'other_field';
} else if (16 < $now) {
$sql .= 'something_else';
} else {
$sql .= 'last_field';
}
$sql .= '="'.date('o-m-d H:i').'" WHERE badge_number="'.$_POST['employee'].'"';
$sendresult = mysql_query($sql);
That code isn’t suitable for cut/paste, it’s more just to show you the kind of checking that you’d (I think) need to implement.