Use PHP to log "time in classroom" on form in web app

I am writing a small web app in PHP with MySQL. I need to record the time that the administrator was in the classroom. In other words, the start time would begin when the form first loads... the finish time would be upon submit. I am using Dreamweaver for the development environment... Should I set the unix timestamp in the forma and then create  a stored procedure that takes the submit time minus the start time and then record that value in one of the fields??
LVL 2
smetterdAsked:
Who is Participating?
 
MasonWolfCommented:
That's a good solution. Here's how to implement the php bits:

somewhere in the form display this code - <input type='hidden' name='starttime' value='<?=time();?>' />

When you process the form, use this bit of code: $classtime = time() - $_POST['starttime'];

Save $classtime to your database. To make it more readable, you can break it into hours, minutes, and seconds like so:
$classtimeStr = floor($classtime / 3600).":".substr("0".(($classtime / 60) % 60),-2).":".substr("0".($classtime % 60),-2);
0
 
smetterdAuthor Commented:
Makes good sense. Any advice on how I would write the SP in MySQL?
0
 
MasonWolfCommented:
SP? not sure what you mean...
0
 
smetterdAuthor Commented:
Stored Procedure
0
 
MasonWolfCommented:
I guess I'm unfamiliar with that style of development, you may need to post that question in the MySQL forum.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.