Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6761173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:09:16+00:00 2026-05-26T14:09:16+00:00

I Have a form to add a product into a database table called ‘Products’

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:09:16+00:00Added an answer on May 26, 2026 at 2:09 pm

    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.

    $q = "INSERT INTO product (`name`) VALUES ('my cool thing')";
    $r = mysql_query($q);
    
    $productId = mysql_insert_id ();
    
    $q = "INSERT INTO product_category (`product_id`, `category_id`) VALUES ({$productId},  {$categoryId})";
    $r = mysql_query($q);
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this form: <form method=post action=mypage.php orderform= name= id=orderform> <a id=add>+</a> <table width=533
I have a product registration form that allows the user to add additional product
I have form, where some fields are looks like rows, so I can add/delete
I have a form which users can add controls to and when they right
I have a form in witch users can add their working hours view them
I have a form where users can add input fields with jQuery. <input type="text"
I have a form and I want to add a select location option. How
I have a form a user can enter their name, then it will add
Hoi! I have a form I wish to submit, but I need to add
I have a bound form in microsoft access that allows a user to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.