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
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.
how do I get the user_id
from the user
table to store into the message
table?
在登录会话期间存储用户数据,如$_SESSION['user'];
$msg->user_id = $_SESSION['user']['user_id'];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.