Paano po kaya yung isang button lang ng Log in at Log out. Pag nag log in yung user mag didisplay sa Time In then pag nag log in uli yung user sa time Out naman
PHP:
//log in
<?php
require_once 'admin/connect.php';
$student = $_POST['student'];
$time = date("H:i", strtotime("+7 HOURS"));
$date = date("Y-m-d", strtotime("+7 HOURS"));
$q_student = $conn->query("SELECT * FROM `student` WHERE `student_no` = '$student'") or die(mysqli_error());
$f_student = $q_student->fetch_array();
$student_name = $f_student['firstname']." ".$f_student['lastname'];
$conn->query("INSERT INTO `time` VALUES('', '$student', '$student_name', '$time', '$date')") or die(mysqli_error());
echo "<h3 class = 'text-muted'>".$student_name." <label class = 'text-info'>at ".date("h:i a", strtotime($time))."</label></h3>";
Code:
//log in javascript
$(document).ready(function(){
$error = $('<center><h2 class = "text-danger">You are not a student here...<h2></center>');
$error1 = $('<center><h2 class = "text-danger">Please fill up the field<h2></center>');
$('#login').click(function(){
$error.remove();
$error1.remove();
$student = $('#student').val();
if($student == ""){
$error1.appendTo('#error');
}else{
$.post('check.php', {student: $student},
function(show){
if(show == 'Success'){
$.ajax({
type: 'POST',
url: 'login.php',
data: {
student: $student
},
success: function(result){
$result = $('<h2 class = "text-warning">You have been login:</h2>' + result).appendTo('#result');
$('#student').val('');
setTimeout(function(){
$result.remove();
}, 10000);
}
});
}else{
$('#student').val('');
$error.appendTo('#error');
}
}
)
}
});
});
Last edited: