I'm Trying to INSERT Data into mysql which is generated from biomatric attendance device. Currently when the page loads all the data in the device will be displaying in a table.
what i wanted to do is to save these data into mysql database. i have tried few codes none of these code works for me . please let me know how can i do this .
<?php include 'db.php'; ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<!-- <script type="text/javascript" src="load.js"></script> -->
<link rel="stylesheet" href="style.css">
<title>Live Attendance</title>
</head>
<?php
include("zklib/zklib.php");
$zk = new ZKLib("192.168.1.3", 4370);
$ret = $zk->connect();
sleep(1);
if ( $ret ):
$zk->disableDevice();
sleep(1);
?>
<body>
<table border="1" cellpadding="5" cellspacing="2" style="float: left; margin-right: 10px;">
<tr>
<th colspan="5">Data User</th>
</tr>
<tr>
<th>UID</th>
<th>ID</th>
<th>Name</th>
<th>Role</th>
<th>Password</th>
</tr>
<?php
try {
//$zk->setUser(1, '1', 'Admin', '', LEVEL_ADMIN);
$user = $zk->getUser();
sleep(1);
while(list($uid, $userdata) = each($user)):
if ($userdata[2] == LEVEL_ADMIN)
$role = 'ADMIN';
elseif ($userdata[2] == LEVEL_USER)
$role = 'USER';
else
$role = 'Unknown';
?>
<tr>
<td><?php echo $uid ?></td>
<td><?php echo $userdata[0] ?></td>
<td><?php echo $userdata[1] ?></td>
<td><?php echo $role ?></td>
<td><?php echo $userdata[3] ?> </td>
</tr>
<?php
endwhile;
} catch (Exception $e) {
header("HTTP/1.0 404 Not Found");
header('HTTP', true, 500); // 500 internal server error
}
//$zk->clearAdmin();
if (isset($_POST['create_post'])) {
$query = "INSERT INTO attendance(idx)";
$query .= "VALUES ($id)";
$submittodbquery = mysqli_query($con,$query);
if (!$submittodbquery) {
die("Failed up upload " . mysqli_error($con));
}else {
echo "updated";
}
}
?>
</table>
<button id="submit" type="submit" name="create_post" class="btn btn-danger">Submit New Post</button>
<?php
$name = $userdata[1];
$attendance = $zk->getAttendance();
sleep(1);
while(list($idx, $attendancedata ) = each($attendance)):
if ( $attendancedata[2] == 1 )
$status = 'Check Out';
else
$status = 'Check In';
?>
<?php $idx ?>
<?php $attendancedata[0] ?>
<?php $attendancedata[1] ?>
<?php $status ?>
<?php date( "d-m-Y", strtotime( $attendancedata[3] ) ) ?>
<?php date( "H:i:s", strtotime( $attendancedata[3] ) ) ?>
<?php
// custom code
if (isset($_POST['submit'])) {
$query = "INSERT INTO attendance(idx)";
$query .= "VALUES ($idx)";
$submittodbquery = mysqli_query($con,$query);
if (!$submittodbquery) {
die("Failed up upload " . mysqli_error($con));
}else {
echo "updated";
}
}
?>
<?php
endwhile
?>
</table>
<input type="submit" name="submit" value="Update Database">
<?php
$zk->enableDevice();
sleep(1);
$zk->disconnect();
endif
?>
</body>
</html>
Thanks for reading my question ..