I'm having trouble with getting the time and date on a checkbox change.
I have a MySQL database named "panel" which is filled with entries of users, every entry has a "status" field in the database, which is either "1" or "0". I'm using this status to see who's online and style the checkboxes as buttons, 1 = green, 0 = gray.
Now I want to get the current system time whenever this status changes and write it into a text file.
For example: When the status changes from 0 to 1, write the following text into a document: [Current time] + [Name of the user from MySQL database] + "logged in"
When the status changes from 1 to 0, write: [Current time] + [Name of the user from mySQL database] + "logged out"
Heres my code:
#this is where I change the status field in MySQL
<?php
$id = $_POST["id"];
$update = mysql_query("update panel
SET status = CASE
WHEN status = '1' THEN '0'
WHEN status = '0' THEN '1'
END
WHERE id = $id")
?>
#this is where I execute the function
<td>
<script type="text/javascript" src="scripte/jquery-2.1.4.min.js"></script>
<script>
function save_checkbox(id)
{
$.post( 'save_check.php' , { checked : $(this).attr("checked"), id: id });
}
</script>
<div class="switch anws">
<input type="checkbox" name="anw_status" value="1" onchange="save_checkbox(<?php echo "$row->id"; ?>);" <?php if ($row->status==1) echo "checked";?>>
<label class="label"><p><?php echo "$row->gender $row->person";?></p></label>
</div>
</td>