title: PHP and HTML select tag
body: <p>I have started with PHP and HTML and would like to execute simple code with three drop-down lists (select tag). But when I make selection from one, the other two selected values disappear. Should I save values when submitting them and then echo. If yes, how can I do it. Sample code will be appreciated.</p>
  
  <pre><code>    &lt;?php // formtest_2.php 
  
  $name_vid = $name_type = $name_model = "";
  
  if (isset($_POST['vid']))$name_vid=($_POST['vid']);
  else $name_vid="no";
  
  if (isset($_POST['type']))$name_type=sanitizeString($_POST['type']);
  else $name_type="no";
  
  if (isset($_POST['model']))$name_model=sanitizeString($_POST['model']);
  else $name_model="no";
  
  echo &lt;&lt;&lt;_END
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Form Test Two&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
      Make your selection:
  
  &lt;form action="formtest_2.php" method="post"&gt;
  
      &lt;select name="vid" size="1"&gt;
  
      &lt;option value="" selected&gt;Product&lt;/option&gt;
  
      &lt;option value = "apple"&gt;apple&lt;/option&gt;
      &lt;option value = "cherry"&gt;cherry&lt;/option&gt;
      &lt;option value = "orange"&gt;orange&lt;/option&gt;
  
      &lt;/select&gt;
  
  &lt;input type="submit"/&gt;&lt;br /&gt;        
  
      &lt;select name="type" size="1"&gt;
  
      &lt;option value="" selected&gt;Color&lt;/option&gt;
  
      &lt;option value = "green"&gt;green&lt;/option&gt;
      &lt;option value = "red"&gt;red&lt;/option&gt;
      &lt;option value = "orange"&gt;orange&lt;/option&gt;
  
      &lt;/select&gt;
  
  &lt;input type="submit"/&gt;&lt;br /&gt;        
  
      &lt;select name="model" size="1"&gt;
  
      &lt;option value="" selected&gt;Model&lt;/option&gt;
  
      &lt;option value = "1-a"&gt;1-a&lt;/option&gt;
      &lt;option value = "2-b"&gt;2-b&lt;/option&gt;
      &lt;option value = "3-c"&gt;3-c&lt;/option&gt;
  
      &lt;/select&gt;
  
  &lt;input type="submit"/&gt;&lt;br /&gt;
  
      &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  _END;
  
  echo "Your selection is: $name_vid and $name_type and $name_model"; 
  
  function sanitizeString($var)
  {
      $var = stripslashes($var);
      $var = htmlentities($var);
      $var = strip_tags($var);
  
      return $var;
  }
  ?&gt;
  </code></pre>