I changed it to the following, and it is now returning 0, not 1 like it should. Any ideas?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/structure.css">
<script type="text/javascript">
window.onload = function () {
var inputs = document.getElementsByTagName('input');
for (i = 0; i < inputs.length; i++) {
inputs[i].onkeyup = function () {
if (this.value.match(/^([0-9][0-9][0-9][0-9][0-9])$/)) {
document.forms["punch"].submit();
}
};
}
};
$("form").bind("keypress", function (e) {
if (e.keyCode == 13) {
$("#btnSearch").attr('value');
//add more buttons here
return false;
}
});
</script>
</head>
<?php
$id = 0;
function getID($staffid, $id, $first_name){
$servername = "localhost";
$username = "root";
$password = "x";
$dbname = "hr";
$conn1 = new mysqli($servername, $username, $password, $dbname);
if ($conn1->connect_error) {
die("Connection failed: " . $conn1->connect_error);
}
$sql = "SELECT id, first_name, employee_id FROM Employees WHERE employee_id='".$staffid."'";
$result = $conn1->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$id = $row["id"];
$first_name = $row["first_name"];
}
return array($id, $first_name);
} else {
return false;
}
$conn1->close();
}
if (isset($_POST['staffid'])){
$staffid = $_REQUEST['staffid'];
if(getID($staffid)) {
$status = "<font color='green'>Punched</font>";
echo $id;
echo $first_name;
} else {
$status = "<font color='red'>Invalid ID, try again</font>";
}
}
?>
<body>
<form class="box login" action="" id="punch" method="post">
<fieldset class="boxBody">
<label>Staff ID</label>
<p><input id="staffid" type="text" autofocus="autofocus" name="staffid"></p>
</fieldset>
<fieldset class="boxBody2">
<center><img src="clock.png" /><br><?php if ($status) {echo $status;} else {echo 'Please enter your Staff ID';}?></center>
</fieldset>
</form>
</body>
</html>