drayarms wrote: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.
The value should be the same or the records cannot be linked together, that is why you use a foreign key.
drayarms wrote:...how do we account for the member_id column?
If you don't auto_increment your primary key, you can use a custom number. Maybe count the number of rows from the blog table then use that value
Code: Select all
<?php
$queryC = "SELECT * FROM blogs";
$sql = mysql_query($queryC);
$rows = mysql_num_rows($sql);
$id = $rows + 1;
$query1 = "INSERT INTO blogs (blog_id, title, entry, blog_date) VALUES ('$id', '{$_POST['title']}', '{$_POST['entry']}', NOW())";
// and
$query2 = mysql_query("INSERT INTO members
(id, username, firstname, lastname, password, date, ip)
VALUES ('$id', '$_POST[username]','$_POST[firstname]','$_POST[lastname]','$_POST[password]','$date','$ip')")
or die ("Error - Couldn't register user.");
?>
Both tables contain the same value for primary key (blog_id) and foreign key (id)