I Have a form to add a product into a database table called ‘Products’ on this form is also a ul with checkboxes for categories, a product can be in multiple categories and therefore when the form is submitted I need to update the product table and the product_categories table.
The Product table will hold the product ID and the product_categories table will hold the product ID only with the category ID therefore creating a One to Many relationship.
However this is where I am stumped, I can get the product written in fine but I am unsure as to the syntax to write to the product_categories table as well.
Can anyone help me out.
There is no code yet as I don’t know what to write!
Thanks
Justin
You need to write two SQL statements. After the first SQL statement you need the ID of the product you have just inserted – you can do this as follows.
Note: This is a pretty naive way of handling this, but it will get you started. You may want to look into using an MVC framework and PDO or ORM’S (or another form of database abstraction) etc to make your life easier.