Foreign key not populating in child table with mysql. Total newbie in all things programming and sql. Creating Web site Form to populate person data using PHP/MYSQL which then launches a secondary Web Site Form to populate car maintenance data. Problem is the Foreign Key from the Parent Table is not updating the Child table. Any help is much appreciated.
Parent Table:
$sql = "CREATE TABLE persons
(
Firstname CHAR(15),
Lastname CHAR(15),
Age INT,
PRIMARY KEY(Firstname)
)";
Child Table:
$sql = "CREATE TABLE cardata
(
CID INT NOT NULL AUTO_INCREMENT,
Firstname CHAR(15) NOT NULL,
Manufacturer CHAR(25),
Model CHAR(15),
Year INT,
`Oil Miles` INT,
`Oil Date` DATE,
`Rotation Miles` INT,
`Rotation Date` DATE,
PRIMARY KEY(CID),
FOREIGN KEY (Firstname) REFERENCES persons (Firstname)
ON UPDATE CASCADE ON DELETE CASCADE
)";
Parent Table Insert:
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
Child Table Insert:
$sql="INSERT INTO cardata (Firstname,Manufacturer)
VALUES
('LAST_INSERT_ID()','$_POST[manufacturer]')";