January 8th, 2013, 08:06 AM
How to insert an auto-generated ID of one table into another table's ID
I am trying to make a project which is an Online shopping website. I have three tables,namely, Category Table, Sub-Category Table and Products table. In category table I have CategoryID and CategoryName as the two fileds.In Sub-Category table I have CategoryID, Sub-CategoryID and SubCategoryName as the fields, and in products table I have CategoryID, SubCategoryID , ProductID and ProductName.
Now in category table , the categoryID is autogenerated and set as primary key.In sub-Category table, the none of the keys are auto generated and both the categoryID and subCategory ID are set to combined primary keys. Now ,when I insert a categoryName into the category table, I want the CategoryID(auto-generated) to be inserted in the categoryID column of the SubCategory table and the CategoryID column of the ProductTable. There is a lot of content in the net on this matter, but none solves exactly my problem.
January 8th, 2013, 05:15 PM
Run the following SQL after your first insert - but it, of course, depends on the database system you are using:
Last edited by AndrewSW; January 8th, 2013 at 05:21 PM.
extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used." the docs
January 8th, 2013, 07:16 PM
All Connected World
All Connected World।Evrey World Tips,Seo Tips,Haking Tips,Internet Marketing,Wordpress,Jomla,Software,Multimedia,Blogspot,Online Marketing,Online Income & Mane More.