javascript - Write time and date on checkbox change into a textfile -


i'm having trouble getting time , date on checkbox change.

i have mysql database named "panel" filled entries of users, every entry has "status" field in database, either "1" or "0". i'm using status see who's online , style checkboxes buttons, 1 = green, 0 = gray.

now want current system time whenever status changes , write text file.

for example: when status changes 0 1, write following text document: [current time] + [name of user mysql database] + "logged in"

when status changes 1 0, write: [current time] + [name of user mysql database] + "logged out"

heres code:

#this change status field in mysql  <?php $id = $_post["id"]; $update = mysql_query("update panel      set status = case         when status = '1' '0'         when status = '0' '1'               end  id = $id") ?>  #this execute 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> 

i recomend making seperate table in database this, instead of writing text file.

however, how can write txt file: lets assume have created text file called log.txt in same folder save_check.php when save_check.php called can this:

first add sql query new status , user name , set them variables $state , $name

$my_file = 'log.txt'; $handle = fopen($my_file, 'a') or die('cannot open file:  '.$my_file);  if ($state == 0 {   $data = "\n" . date('m/d/y h:i:s a', time()) . " " . $name . " logged out"; } else {   $data = "\n" . date('m/d/y h:i:s a', time()) . " " . $name . " logged in"; }  fwrite($handle, $data); fclose($handle); 
  • \n ensure on new line.
  • date('m/d/y h:i:s a', time()) current time , format it
  • fwrite append file

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -