Jump to content

cdecker15

New Members
  • Posts

    3
  • Joined

  • Last visited

cdecker15's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I plan on using the ID later in the file, for a different MySQL statement. So what should I be using for this?
  2. 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>
  3. The below code works and all, but I would like to figure out how to get rid of the global variable. I tried without declaring it as a global variable and it did not work. Any other way to do that? Also, how would I go about returning two variables(right now I am returning $id), how can I return both $id and $first_name from the database. <!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){ $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); global $id; if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $id = $row["id"]; } return $id; } else { return false; } $conn1->close(); } if (isset($_POST['staffid'])){ $staffid = $_REQUEST['staffid']; if(getID($staffid)) { $status = "<font color='green'>Punched</font>"; echo $id; } 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>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.