Insert id obtained from another table

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 save the user who posted the message in the database. The codes I wrote allow me to save a message sent to the database but notuser_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() is the sql statement that inserts my query.

How do I get user_idfrom a table userto be stored in a table message?

+4
source share
1 answer

store user data during session login, for example $_SESSION['user'];

$msg->user_id = $_SESSION['user']['user_id'];
0
source

All Articles