-2

I want to create a page which allows a user to select colours (among the listed ones, via checkboxes). When the user clicks on the submit button, all the selected colours should get displayed with their corresponding colours as their font colour.

Here is my code:

<?php 
if(!isset($_POST['button'])) { 
?>
    Colours<br>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method=post>
    <input type="checkbox" name="colours[]" value="Red">Red<br>
    <input type="checkbox" name="colours[]" value="Blue">Blue<br>
    <input type="checkbox" name="colours[]" value="Green">Green<br>
    <input type="checkbox" name="colours[]" value="Yellow">Yellow<br>
    <input type="checkbox" name="colours[]" value="Pink">Pink<br>
    <input type="submit" name="button" value="Show"> </form>
    <?php
} else {
    if (isset($_POST['colours'])) {
        echo "Colours selected are:<br><UL type=circle>";
        foreach($_POST['colours'] as $color) 
            echo "<LI><font color='echo $color'; >$color</font>";
        echo"</UL>";
    } else { 
        echo "No colour selected"; 
    }
} 
?>

There is a bug somewhere, the font colors are not as expected. I want it like this image below:

Screenshot

trincot
  • 317,000
  • 35
  • 244
  • 286
  • I suggest you clear doubts on HTML first.http://www.w3schools.com/html/ – Amit Ray Jun 03 '16 at 10:41
  • @Ravi-Hirani There was only one error, and now resolved.. – RisingUnderDog Jun 03 '16 at 10:47
  • @Amit-Ray What do you mean? I know HTML, and the HTML code is correct. – RisingUnderDog Jun 03 '16 at 10:49
  • @RisingUnderDog Whether it should be method=post or method="post" ? – Amit Ray Jun 03 '16 at 10:52
  • 1
    @RisingUnderDog: You haven't completed tag also. – Ravi Hirani Jun 03 '16 at 10:53
  • 1
    HTML Tag. Not Supported in HTML5. Reference: [Font Tag](http://www.w3schools.com/tags/tag_font.asp) – AlexG Jun 03 '16 at 11:27
  • @AmitRay What I know is method=post, method='post' and method="post" all three are correct, am I wrong? – RisingUnderDog Jun 03 '16 at 17:20
  • @RaviHirani It is not mandatory to close
  • tag, check this out http://stackoverflow.com/questions/20550788/does-the-li-tag-in-html-have-an-ending-tag
  • – RisingUnderDog Jun 03 '16 at 17:24
  • @RisingUnderDog You can never be wrong because you read and understand everything partially. Read this again for li tag "An li element's end tag may be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element." Is the last li element followed by another li element in the loop. Also can you show me an example in stackoverflow where method=post is used. – Amit Ray Jun 03 '16 at 17:46
  • @AmitRay Well that was an elucidative example. Do it for yourself
  • needs not to be closed, it's a kinda empty tag. And regarding method=post issue, it wasn't a complex code so I didn't use either of them ("" or ''), most of the times I use single codes but here it wasn't needed at all.
  • – RisingUnderDog Jun 03 '16 at 18:34