INSERT INTO different tables based on the option selected from dropdown menu

How do I create an if statement to check the selected option from the dropdown menu?
if(isset($_POST[‘action’]))
{
$selected_val = $_POST[‘action’];
if($selected_val = 1)
{
INSERT INTO…

You haven’t really provided enough information about - Why you have different tables that you need to distinguish between, how much of the query is the same/different depending on the choice made, how many choices the are, and what is the mapping between the input value and the specific query? Basically, what are all the conditions and limits that need to be considered to provide the best solution.

However, if you find yourself writing out conditional logic for each possible numerical input value, it’s a sign you are doing this the hardest way possible. You should instead use a data-driven design, where the mapping of input to output is defined in a data structure (array or database table), then use general purpose logic to perform the operation on the variable data values.

BTW - one = is an assignment operator, two == is a comparison operator, so your posted example will always result in a true conditional test for any non-zero right-hand value.

Sponsor our Newsletter | Privacy Policy | Terms of Service