Even employees with trust-based working hours need to track times. With a small script, calling a webpage inserts the current timestamp in a database to track clock-in and clock-out timestamps.
<?php
$servername = "localhost";
$username = "d03ca9da";
$password = "";
$dbname = "d03ca9da";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO `timesheet` (`idt`, `ts`) VALUES (NULL, CURRENT_TIMESTAMP)";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
create table timesheet
(
idt int auto_increment
primary key,
ts datetime default CURRENT_TIMESTAMP not null
);