php - insert foreign key value from parent table into child table
I have two tables Loan(Parent Table) and Receipt(Child table)what i want to do is when a row is inserted in the parent table(loan) i want the foreign key(app_file_id) to also be inserted in the child table
$values = $_POST;
foreach ($values as &$value) {
$value = mysql_real_escape_string($value);
}
$sql1="INSERT INTO loan (loan_id,officer_department,app_file_id)
VALUES ('','$values[officer_department]','$values[app_file_id]')";
$result = mysql_query($sql1);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
I have managed to insert data in the parent table but the child table (receipt), and the foreign key (app_file_id), how do i get it to be inserted in the receipt table as well
Answer
Solution:
Try this