If the primary key of an sql table is being used as a foreign key of another table, when entering the values of the columns of the second table in an insert query, what would the value of the foreign key be. Say for example we had a table called members whose primary key (member_id) is a foreign key column of another table blogs. If we wrote a query to insert values into the blogs table like the one below, how do we account for the member_id column?
$query = “INSERT INTO blogs (blog_id, title, entry, blog_date) VALUES (0, ‘{$_POST[‘title’]}’, ‘{$_POST[‘entry’]}’, NOW())”;
Just in case it might be helpful, here is the query for inserting values into the members table:
$query = mysql_query(“INSERT INTO members
(id, username, firstname, lastname, password, date, ip)
VALUES (0, ‘$_POST[username]’,’$_POST[firstname]’,’$_POST[lastname]’,’$_POST[password]’,’$date’,’$ip’)”)
or die (“Error - Couldn’t register user.”);