Post back the data if validation fails for "Select"
<p>Once submitted selected option, the data is not stored. 
just want to know how to post back the data if validation fails</p>

<p>The following line doesnt really work for me.</p>

<pre><code>    &lt;select id="numbers" name="numbers" value="&lt;?php echo (isset($_POST['numbers'])) ? $_POST['numbers'] : " "; ?&gt;"/&gt;
</code></pre>

<p>if someone could give me a hand?</p>

<p>Many thanks, here is my code</p>

<pre><code>&lt;?php

if(isset($_POST['numbers']) &amp;&amp;($_POST['fruits']) &amp;&amp; $_POST['numbers'] != "null" &amp;&amp; $_POST['fruits'] !== "null")
{
  echo "Thank you!";
} elseif  (isset($_POST['numbers']) &amp;&amp; $_POST['numbers'] = "null") {
    echo "you forgot to choose a number";
    }
    elseif(isset($_POST['fruits']) &amp;&amp; $_POST['fruits'] = "null")
{
    echo "you forgot to choose fruit name";
    }

?&gt;



  &lt;form id="form" name="form"  method="post" action=""&gt;

      &lt;label for="expiry"&gt;Select&lt;/label&gt;
                &lt;select id="numbers" name="numbers" value="&lt;?php echo (isset($_POST['numbers'])) ? $_POST['numbers'] : " "; ?&gt;"/&gt;
                &lt;option value="null" selected="selected"&gt;-&lt;/option&gt;
                &lt;option  value="01"&gt;01&lt;/option&gt;
                &lt;option value="02"&gt;02&lt;/option&gt;
                &lt;option value="03"&gt;03&lt;/option&gt;
              &lt;/select&gt;

                &lt;select id="fruits" name="fruits" value="&lt;?php echo (isset($_POST['fruits']))? $_POST['fruits'] : ''; ?&gt;"/&gt;
                &lt;option value="null" selected="selected"&gt;-&lt;/option&gt;
                &lt;option value="Apple"&gt;Apple&lt;/option&gt;
                &lt;option value="Banana"&gt;Banana&lt;/option&gt;
                &lt;option value="Pear"&gt;Pear&lt;/option&gt;

              &lt;/select&gt;

   &lt;input type="submit" value="Send"  /&gt;
  &lt;/form&gt;
</code></pre>

<p>Solved it, Maybe not a best way, but at least got it sorted:</p>

<pre><code>&lt;?php
$item = null; # 
$itemyear = null; 

if(isset($_POST['numbers'])){
$item = $_POST['numbers'];
}
if(isset($_POST['fruits'])){
$itemyear = $_POST['fruits'];
}



if(isset($item) &amp;&amp; isset($itemyear) &amp;&amp; $item != "null" &amp;&amp; $itemyear !== "null")
{
  echo "Thank you!";
} elseif  ($item == "null") {
    echo "you forgot to choose a number";
    }
    elseif($itemyear == "null")
{
echo "you forgot to choose fruit name";
}



?&gt;



  &lt;form id="form" name="form"  method="post" action=""&gt;

      &lt;label for="expiry"&gt;Select&lt;/label&gt;
            &lt;select id="numbers" name="numbers" /&gt;
                &lt;option value="null" selected="selected"&gt;-&lt;/option&gt;
                &lt;option  value="01" &lt;?php if($item == '01'): echo "selected='selected'"; endif; ?&gt;&gt;01&lt;/option&gt;
                &lt;option value="02" &lt;?php if($item == '02'): echo "selected='selected'"; endif; ?&gt;&gt;02&lt;/option&gt;
                &lt;option value="03" &lt;?php if($item == '03'): echo "selected='selected'"; endif; ?&gt;&gt;03&lt;/option&gt;
              &lt;/select&gt;

              &lt;select id="fruits" name="fruits" /&gt;
                &lt;option value="null" selected="selected"&gt;-&lt;/option&gt;
                &lt;option value="Apple"&lt;?php if($itemyear == 'Apple'): echo "selected='selected'"; endif; ?&gt; &gt;Apple&lt;/option&gt;
                &lt;option value="Banana"&lt;?php if($itemyear == 'Banana'): echo "selected='selected'"; endif; ?&gt;&gt;Banana&lt;/option&gt;
                &lt;option value="Pear"&lt;?php if($itemyear == 'Pear'): echo "selected='selected'"; endif; ?&gt;&gt;Pear&lt;/option&gt;

              &lt;/select&gt;

   &lt;input type="submit" value="Send"  /&gt;
  &lt;/form&gt;


&lt;?php 
echo $item ."-". $itemyear;
?&gt;
</code></pre>
