user1444442
user1444442

Reputation: 109

Inserting into MySQL database

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.

enter image description here

How could I go about this please ?? Thanks in advance.

Upvotes: 1

Views: 117

Answers (1)

juergen d
juergen d

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

Related Questions