Skip to content
Advertisement

Inserting data into MySQL from a dropdown

I’m trying to make a dropdown list that allows users to select a training program that matches their needs, so when they select it, the option will go into a table in the MySQL database.

This is my HTML form:

What I need is an SQL query that will go with it, so when they select ‘Example option 3’, it will be entered into the database in a column called method. I should be inserted into method with the values (depending on their option in the dropdown). For example, if the user selected Example option 2 it would be inserted into method with the values Example option 2.

How do I populate database tables/columns with dropdowns?

Advertisement

Answer

First of all give name to your select. In this case I have given training

Now in your sessionreq.php you can fetch the value through $_POST like

Now you can run the query to insert. Given is a prepared statement (prefered)

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement