title: Colouring User Inputted Text depending on colour selection PHP
body: <p>I've been asked to create a PHP page that will contain a form. This form should allow for a user to input a word and select a colour. Based on their selections the page should then echo out the user's word in the colour of their choosing. I began to try and implement it however ran into some problems. My code is below:</p>
  
  <pre><code>&lt;?php
  echo "
  &lt;html&gt; 
  &lt;head&gt; 
    &lt;title&gt;Colour Text&lt;/title&gt; 
  &lt;/head&gt; 
  &lt;body&gt; 
    &lt;form name='colour_text' onsubmit='colour_text()' method='POST'&gt;
      Word: &lt;input type='text' name='word' /&gt;&lt;br /&gt;
      Choose the colors: 
        &lt;input type='radio' name='colour' value='bk' checked='checked' /&gt; Black
        &lt;input type='radio' name='colour' value='rd' /&gt; Red
        &lt;input type='radio' name='colour' value='be' /&gt; Blue
        &lt;input type='radio' name='colour' value='yw' /&gt; Yellow
        &lt;input type='submit' /&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  &lt;/head&gt;
  &lt;/html&gt;";
  
  function colour_text($word, $colour)
  {
  
  $word = $_POST['word'];
  $colour = $_POST['colour'];
  
      if ($colour == 'bk' ) 
      {
          echo '&lt;div style=\"color:black;\"&gt;$word&lt;/div&gt;';
      }
      if ($colour == 'rd' ) 
      {
          echo '&lt;div style=\"color:red;\"&gt;$word&lt;/div&gt;';
      }
      if ($colour == 'be' ) 
      {
          echo '&lt;div style=\"color:blue;\"&gt;$word&lt;/div&gt;';
      }
      if ($colour == 'yw' ) 
      {
          echo '&lt;div style=\"color:yellow;\"&gt;$word&lt;/div&gt;';
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Being new to PHP, I have searched and found some similar questions but nothing that is directly applicable to this.</p>