How to add a value which is a primary key of another table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    How to add a value which is a primary key of another table

    I'm using php and mysql. There are 2 tables called vehicles(vehicl eid,make,model) and images(imageid, vehicleid,image path). From php page I want to add vehicle details to the above 2 tables.
    This is my php code
    Code:
    $sql = "INSERT INTO vehicles VALUES('','$make','$model','$type','$year','$month','$fuel','$transmission','$color','$price','$displacement','$milage','$other'), images('','','$filePath')";
    How can I add PK ofvehicles table to the image table.
  • ghjk
    Contributor
    • Jan 2008
    • 250

    #2
    I have done it. From using the following function you can get PK of the last inserted record.

    Code:
    mysql_insert_id());

    Comment

    Working...