adamrifau Posted November 24, 2016 Share Posted November 24, 2016 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 .. Quote Link to comment https://forums.phpfreaks.com/topic/302607-how-can-i-insert-data-from-biomatric-device-to-mysql-php/ Share on other sites More sharing options...
Solution mac_gyver Posted November 24, 2016 Solution Share Posted November 24, 2016 it would be helpful if you define what the work-flow (steps) is (are) before you try to write code. it will also help us if you tell us what the work-flow is supposed to be. something like - 1) connect to device, 2) retrieve user and attendance data, 3) display data in forms, 4) submit form, 5) store submitted data into database table. are you displaying the data as part of the learning/debugging process and you want to 'automatically' insert the data into the database tables OR are you trying to display the data in a form and you will manually submit the form to cause the data to be inserted into the database tables? next, you need to separate the different concerns in your code. any form processing code should be near the top of your file and come before you output any html to the page. the form processing code would come before the <!DOCTYPE tag. all the form processing code would be grouped together. to display the page, your code is retrieving user and attendance data from the time-clock. the code to retrieve this data and store it in php variables should be grouped together and come before you start outputting the html document. you would then simply loop over this data when you output the html document. if you are outputting the data in a form, perhaps to allow it to be verified and edited by a manager, you would need to output it using form fields, in a valid form. there are currently no <form...> tag(s) and no data-input form fields in your code. your attendance data output doesn't even have a <table> tag, no <tr></tr> <td></td> tags and no echo statements for the data. Quote Link to comment https://forums.phpfreaks.com/topic/302607-how-can-i-insert-data-from-biomatric-device-to-mysql-php/#findComment-1539647 Share on other sites More sharing options...
adamrifau Posted November 26, 2016 Author Share Posted November 26, 2016 Here is current steps i'm able to do following steps with the current code .. 1- connecting the device . 2 - pull the current data from attendance device . 3 dispay the data in current page (in this case index.php) pulled information 1- user id (from attendance device) 2- username 3- index number 4- check in status 5-date 6- time i'm trying to manully insert the data (via button) into mysql database . if user pressed the button which currently unable to process i've removed form fields and tables because i don't want to display data in current page. Quote Link to comment https://forums.phpfreaks.com/topic/302607-how-can-i-insert-data-from-biomatric-device-to-mysql-php/#findComment-1539694 Share on other sites More sharing options...
adamrifau Posted November 28, 2016 Author Share Posted November 28, 2016 thanks code was fixed by adding a form and clearing some old codes . Quote Link to comment https://forums.phpfreaks.com/topic/302607-how-can-i-insert-data-from-biomatric-device-to-mysql-php/#findComment-1539766 Share on other sites More sharing options...
SITASA Posted July 11, 2019 Share Posted July 11, 2019 Hello Adam, could you solve the issue? Quote Link to comment https://forums.phpfreaks.com/topic/302607-how-can-i-insert-data-from-biomatric-device-to-mysql-php/#findComment-1568293 Share on other sites More sharing options...
Meemkhaan Posted July 26, 2019 Share Posted July 26, 2019 On 11/28/2016 at 3:23 PM, adamrifau said: thanks code was fixed by adding a form and clearing some old codes . Dear Adam please share your code Quote Link to comment https://forums.phpfreaks.com/topic/302607-how-can-i-insert-data-from-biomatric-device-to-mysql-php/#findComment-1568707 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.