0
if(isset($_POST["marketing"])){ 
  foreach($_POST as $key => $value){
   if(strlen($value)<1)
    continue;
    echo "<option value='".$value."' selected >".$value."</option>";        
}

enter image description here

I have create dynamic options in php. All option are selected by default . I want to add all selected option into database. How can i check options is selected or not?

jh314
  • 27,144
  • 16
  • 62
  • 82
Syeda Shah
  • 81
  • 1
  • 5

1 Answers1

0

Try this, we do not know what else is being posted through your form though..

if (isset($_POST["marketing"])){
    foreach($_POST as $key => $value)
        {
        $iselected = ($value == $_POST['marketing']) ? 'selected' : '';
        echo "<option value='" . $value . "' $iselected>" . $value . "</option>";
        }
    }
NiCk Newman
  • 1,716
  • 7
  • 23
  • 48