Reputation: 109
I am trying to insert data into MySQL database. For each of the data been inserted I want the username to be added so as to keep track of the user the insert that data.Here is my sample query below but the username is not inserting.
$username = $_SESSION['log']['username'];
$Query = "INSERT INTO core_modules
(username,courseID,title,credits)
VALUES ('$username',SELECT ID,title,credits FROM module
WHERE ID IN ('CS4150','CS4403','CS4407','CS4501','CS4504','CS4614'))";
mysql_query($Query);
echo $Query. '<br />';
This is what my database looks like and I need the username inserted into each record inserted.
How could I go about this please ?? Thanks in advance.
Upvotes: 1
Views: 117
Reputation: 204904
INSERT INTO core_modules (username,courseID,title,credits)
SELECT '$username', ID, title, credits
FROM module
WHERE ID IN ('CS4150','CS4403','CS4407','CS4501','CS4504','CS4614')
Upvotes: 4