I am working on a little project that I hope to use at work on just a local server.
We operate a golf dome and charge by the amount of time people are in the dome hitting golf balls. I want people to be able to enter their name and a pin that clocks the time that they enter the dome to a database. When they enter they name and pin again the time they exit the dome. Then display the difference in hours and minutes only (people wont hit for a day +). and if possible when they clock out I want it to remove the name from the database.
My database is set up like this:
id-INT(11),nn,ai
name-VARCHAR(45),pk,nn
pin-VARCHAR(4),nn
time_in-TIMESTAMP,nn
time_out-TIMESTAMP,nn
This is what I have so far.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<title>Dome time clock</title>
</head>
<body>
<div id="wrapper">
<div id="content">
<div align="center"><h2><small>time clock</small></h2></div><br>
<table width="100%">
<tr>
<td><?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("timelog") or die(mysql_error());
//This code runs if the form has been submitted
if (isset($_POST['submit'])) {
//This makes sure they did not leave any fields blank
if (!$_POST['name'] | !$_POST['pin'] | !$_POST['pin2'] ) {
die('You did not complete all of the required fields. <a href="javascript:history.go(-1)">Go Back</a>');
}
// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['name'] = addslashes($_POST['name']);
}
$usercheck = $_POST['name'];
$check = mysql_query("SELECT name FROM log WHERE name = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, "'.$_POST['name'].'" is already in use. <a href="javascript:history.go(-1)">Go Back</a>');
}
// this makes sure both passwords entered match
if ($_POST['pin'] != $_POST['pin2']) {
die('Your PIN did not match. <a href="javascript:history.go(-1)">Go Back</a> ');
}
// here we encrypt the password and add slashes if needed
$_POST['pin'] = md5($_POST['pin']);
if (!get_magic_quotes_gpc()) {
$_POST['pin'] = addslashes($_POST['pin']);
$_POST['name'] = addslashes($_POST['name']);
}
// now we insert it into the database
$insert = "INSERT INTO log (name, pin)
VALUES ('".$_POST['name']."', '".$_POST['pin']."')";
$add_member = mysql_query($insert);
?>
<h1>Thank's <?php echo $_POST['name'] ?> you are now clocked inn. Enjoy! <a href="javascript:history.go(-1)">Go Back</a></h1>
<p></p>
<?php
}
else
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td>Username:</td><td>
<input type="text" name="name" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pin" maxlength="10">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pin2" maxlength="10">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit"
value="Clock in/out"></th></tr> </table>
</form>
<?php
}
?>
</td>
</tr>
</table></p>
</div> <!-- end #content -->
</body>
</html>