Link string inserted in a 'sub-category' field to a category

Asked

Viewed 23 times

1

Good night. I have an input 'category', where the user selects the existing categories, and below a field 'subcategory', if the user wishes to register. In Mysql you already have the tables created, they are: tbdcategoria (idCategoria, dscCategoria), and tbdsubcategoria (idSubcategoria, dscSubcategoria, idCategoria).

How can I make when the user clicks 'register', link the subcategory created to the selected category?

  • you are already relating the two tables

1 answer

0

If this is how to do this with php. Simply take the category input data with Get or Post and enter it into the database using a query by PDO or using ORM methods if you are using.

If this is how to do it in the database, you need to create a FOREIGN KEY (FK - Foreign Key) of the category in the subcategory table so you will have a field in the table tbdsubcategory with the idCategory that will be referencing the ID of the category registered in the table of categories. You will simply take the category id and add it to the table entry subcategory

This is the basic relational database. I suggest you study about it for more information

Mysql documentation to create foreign key: Using FOREIGN KEY Constraints

Browser other questions tagged

You are not signed in. Login or sign up in order to post.