By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

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

100+
P: 250
I'm using php and mysql. There are 2 tables called vehicles(vehicleid,make,model) and images(imageid,vehicleid,imagepath). From php page I want to add vehicle details to the above 2 tables.
This is my php code
Expand|Select|Wrap|Line Numbers
  1. $sql = "INSERT INTO vehicles VALUES('','$make','$model','$type','$year','$month','$fuel','$transmission','$color','$price','$displacement','$milage','$other'), images('','','$filePath')";
  2.  
How can I add PK ofvehicles table to the image table.
Jul 28 '11 #1

✓ answered by ghjk

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

Expand|Select|Wrap|Line Numbers
  1. mysql_insert_id());
  2.  

Share this Question
Share on Google+
1 Reply


100+
P: 250
I have done it. From using the following function you can get PK of the last inserted record.

Expand|Select|Wrap|Line Numbers
  1. mysql_insert_id());
  2.  
Jul 28 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.