PHP select from MySQL tables and save in another table ← (PHP, MySQL, HTML)

one text

Solution:

The two dropdown boxes are in separate html forms with separate submit buttons. My guess is that you select the customer, press the submit button, then select a product and press the other submit button. These are 2 separate submits, therefore 2 separate inserts will be executed.

Not to mention that you do not check user inputs before the insert, so the insert will execute even when you load the page, and your code is also completely vulnerable to sql injection attacks.

Solution:

  1. Place the 2 dropdown menus in a single html form with a single submit button.
  2. Check if there was a form submission at all using isset() function before you do the insert.
  3. Validate the user inputs before the insert or use prepared statement.

Source