I have a message table
我有一个消息表
**message**
---------------------------------------
msg_id (AI) | user_id | content
and user table
和用户表
**user**
---------------------------------------
user_id (AI) | email | password | name
I would like to store the user who posted the message into the database. The codes I have written allows me to store the message submitted into the database but not the user_id
我想将发布消息的用户存储到数据库中。我编写的代码允许我将提交的消息存储到数据库中,而不是user_id
if (isset($_POST['submit'])) { // Form has been submitted.
$msg = new msg();
$msg->user_id = ???
$msg->content = trim($_POST['content']);
if ($msg->createMsg()) {
//action
} else {
//action
}
the createMsg()
is a sql statement that inserts my query.
createMsg()是一个插入我的查询的sql语句。
how do I get the user_id
from the user
table to store into the message
table?
如何从用户表中获取user_id以存储到消息表中?
1 个解决方案
#1
1
store user data during login into session like $_SESSION['user'];
在登录会话期间存储用户数据,如$ _SESSION ['user'];
$msg->user_id = $_SESSION['user']['user_id'];
#1
1
store user data during login into session like $_SESSION['user'];
在登录会话期间存储用户数据,如$ _SESSION ['user'];
$msg->user_id = $_SESSION['user']['user_id'];