使用mysql和php从会话中将用户名记录到表中 [英] recording username into table from session with mysql and php
问题描述
我有一个用mysql和php开发的数据库系统,还有一个登录系统,我使用会话,但是当用户添加记录时,我希望它也记录添加它的用户,我认为会话可以允许我要做到这一点,但我失去了如何从会话中检索用户名并将其添加到表中的术语:一个简单插入的示例:
I have a database system developed in mysql and php, with a login system as well, im using sessions,however when a user adds a record I want it to also record the user who added it, im thinking sessions would allow me to do this but im lost interms of how to retrieve the username from the session and add it to a table: example of a simple insert:
INSERT INTO table_name
VALUES (value1, value2, value3)
我希望值3是会话中的用户名,我不确定您需要多少信息来帮助我解决此问题,因此请问合适的情况
I want value 3 to be the username from the sessions, I am not sure how much more information you need to help me to solve this, so ask as you see fit
推荐答案
在用户登录后设置value3 = $_SESSION['username']
,然后将其插入表中.
Set value3 = $_SESSION['username']
after the user has logged in and then insert it into the table.
这是一些伪代码:
$username = $_SESSION['username']
//connect to db
INSERT INTO table_name
VALUES (value1, value2, $username)
//close db connection
会话ID参考: http://php.net/manual/zh/function.session-id.php
这篇关于使用mysql和php从会话中将用户名记录到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!