database - PHP check in and out system

I have a basic knowledge of PHP and I am trying to make a check in and out system by adding a check in time and check out time to a database.

Check in:

session_start();

$_SESSION ['inchecken'] = true;

$tijd = date("H:i:s");

$query = "INSERT INTO tijden(tijdin) VALUES('$tijd')";

$resultaat = mysql_query($query);

Check out:

$tijd = date("H:i:s");

$query = "INSERT INTO tijden(tijduit) VALUES('$tijd')";

$resultaat = mysql_query($query);

unset($session['inchecken']);

The problem is that the check in time and check out time are both saved to a new id in my database (auto increment). Is there someone who can tell me how to add both the check in and check out time in the same database id? Thanks in advance!

网友答案:

You're inserting two rows. That's the reason why you're going to get two entries in your table. You need to use the UPDATE construct for the second piece of code.

You need a way to know the id of the checkin time in order to update it.