I am trying to replicate the following:
php if statement html option value and am following the directions as suggested:
Give name to your select.
<select name="selectedValue">
<option value="Newest">Newest</option>
<option value="Best Sellers">Best Sellers</option>
<option value="Alphabetical">Alphabetical</option>
</select>
In php
Example:
switch($_POST['selectedValue']) {
case 'Newest':
// do Something for Newest
break;
case 'Best Sellers':
// do Something for Best seller
break;
case 'Alphabetical':
// do Something for Alphabetical
break;
default:
// Something went wrong or form has been tampered.
}
However, I am getting the following error:
Notice: Undefined index: selectedValue in C:\xampp\trial.php on line 7
Please help
$_POSTis only filled in when you submit the form. It won't have any values in it when you first load the page. You need to check if the form was submitted before trying to use the parameters.