PHP签入和签出系统 [英] PHP check in and out system

查看:229
本文介绍了PHP签入和签出系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的PHP知识,我试图通过添加一个检查时间和检查时间到数据库进行检入和检出系统。

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.

签到:

session_start();
$_SESSION ['inchecken'] = true;
$tijd = date("H:i:s");
$query = "INSERT INTO tijden(tijdin) VALUES('$tijd')";
$resultaat = mysql_query($query);    

签出:

$tijd = date("H:i:s");
$query = "INSERT INTO tijden(tijduit) VALUES('$tijd')";
$resultaat = mysql_query($query);
unset($session['inchecken']);

问题是检入时间和结帐时间都被保存到我的数据库(自动增量)。是否有人可以告诉我如何在同一个数据库ID添加检入和检出时间?提前感谢!

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!

推荐答案

您插入两行。这就是为什么你要在表中获得两个条目的原因。你需要为第二段代码使用UPDATE结构。

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.

你需要一种方法来知道签入时间的id,以便更新它。

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

$tijd = date("H:i:s");
$query = "UPDATE tijden SET tijduit = '".$tijd."' WHERE id =".$id;
$resultaat = mysql_query($query);
unset($session['inchecken']);

此外,您的会话变量未取消设置。

Also, your session variable isn't getting unset.

更改您的unset($ session ['inchecken']);语句取消设置($ _ SESSION ['inchecken']);

change your unset($session['inchecken']); statement to unset($_SESSION['inchecken']);

这篇关于PHP签入和签出系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆