You might want to use 24-hour bases as a value.
This is because 8-8 = 0
, but 20-8 = 12
. (20:00 is 8pm), meaning they have worked 12 hours.
Also, you should make sure you aren't using any double id
attributes.
Your $hours_worked
hidden field won't work, as php does not work like that.
You will need to store the hours worked for every day seperately.
The way I look at it, your code will not work in any case. I could point out small fixes to you but then you would just bump into the next problem. I feel like you should start by researching how to save the results of this function. You also might want to use javascript to make life easier.
Once you've done this, let me know in a comment and I'll update my answer with an actual fix (if by then an actual fix is possible)
Have a look at this question for creating the ability to actually store multiple form entries:
Storing Form Data as a Session Variable
Once done, I'll assume you'll use $_SESSION
to store these hours per day.
By this point you can just say something like this:
//Checks if the $_SESSION["workedhours"] already has anything stored
//If not, no , beforehand.
if(!isset($_SESSION["workedhours"]){
//this creates the initial session.
$_SESSION["workedhours"] = $hours_worked; }
}
else{
//This adds to it
$_SESSION["workedhours"] .= ",$hours_worked";
}
In this case, you will also want to have the start_session()
running. This goes on the very first line of your file (inbetween the <?php
tags,
<?php
//Checks if a session already exists, if not, start one
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
?>
I also recommend you read this, as it's important to know how to get the inserted data from your form:
http://www.w3schools.com/php/php_forms.asp
edit note:
The $_SESSION
is a temporary thing. It only holds data as long as your browser is open. If you want to store this data permanently, you'll have to use a database. Everything about my answer changes if you use a database, but it doesn't seem like you're using one right now.