![](/img/trans.png)
[英]i want to insert into a table, a data gotten from another table in the same database in php
[英]insert an id gotten from another table
我有一個消息表
**message**
---------------------------------------
msg_id (AI) | user_id | content
和用戶表
**user**
---------------------------------------
user_id (AI) | email | password | name
我想將發布消息的用戶存儲到數據庫中。 我編寫的代碼允許我將提交的消息存儲到數據庫中,而不是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
}
createMsg()
是一個插入我的查詢的sql語句。
如何從user
表中獲取user_id
以存儲到message
表中?
在登錄會話期間存儲用戶數據,如$_SESSION['user'];
$msg->user_id = $_SESSION['user']['user_id'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.