title: setting background of a form
body: <p>I was just messing with PHP trying to get my form to change color when you select a color. for this im using cookies.. only when I press the button at first the background doesnt change but when you press it again it does. why does it doe this?</p>
  
  <p>here's my code (sorry for using html in php): </p>
  
  <pre><code>&lt;?php
  
      $red = "";
      $blue = "";
      $green = "";
      $gold = "";
      $silver = "";
      $purple = "";
  
      $hour = time() + 3600;
  
      if (isset($_POST['order'])) {
          $color = $_POST['order'];
          $$color = "selected";
          setcookie("Free_cookies", $color, $hour);
      }
      else{
          $color = "red";
          $red = "selected";
      }
      if(isset($_COOKIE['Free_cookies'])){
          $color = $_COOKIE['Free_cookies'];
          $$color = "selected";
      }
  
  ?&gt;
  &lt;form method='post'&lt;?php echo "STYLE='background-color:".$color.";'";?&gt; &gt;&lt;p id='txtorder'  &gt;color: &lt;/p&gt;
      &lt;select name='order' id='order'&gt;
          &lt;option value="red"&lt;?php echo $red; ?&gt; &gt;red&lt;/option&gt;
          &lt;option value="blue"&lt;?php echo $blue; ?&gt; &gt;blue&lt;/option&gt;
          &lt;option value="green"&lt;?php echo $green; ?&gt; &gt;green&lt;/option&gt;
          &lt;option value="gold"&lt;?php echo $gold; ?&gt; &gt;gold&lt;/option&gt;
          &lt;option value="silver"&lt;?php echo $silver; ?&gt; &gt;silver&lt;/option&gt;
          &lt;option value="purple"&lt;?php echo $purple; ?&gt; &gt;purple&lt;/option&gt;
      &lt;/select&gt;
      &lt;input type='submit' value='sort'/&gt;
  &lt;/form&gt;
  </code></pre>