what's wrong with my php coding?

Sharky Forums


Results 1 to 3 of 3

Thread: what's wrong with my php coding?

  1. #1
    Goldfish nvd80's Avatar
    Join Date
    Jul 2004
    Location
    Sabah, Malaysia
    Posts
    85

    what's wrong with my php coding?

    when i choose few items from the list in the main page, it will open a new page which will display the no of item choosed and the particular colors. the problem is, when i hit the select button, it prompt "you had choose 0 color.." then there is error at my foreach function..


    1st file selectcolour.php

    <html>
    <head>
    <title>Task 4</title>
    </head>

    <body>
    <table width="42%" border="1" align="center">
    <form name="page1" action="displaycolour.php">
    <tr>
    <td><div align="center"><strong>Please Select Your Favourite Colour:</strong></div></td>
    </tr>
    <tr>
    <td height="89">
    <div align="center">
    <select name="selcolour[]" multiple="multiple" size="4">
    <option>yellow</option>
    <option>blue</option>
    <option>green</option>
    <option>orange</option>
    <option>red</option>
    <option>purple</option>
    </select>
    </div></td>
    </tr>
    <tr>
    <td><p align="center"><input type="submit" name="submit" value="Select"></p></td>
    </tr>
    </form>
    </table>

    </body>
    </html>

    2nd file: displaycolour.php
    <html>
    <head>
    <title>Display Colour</title>
    </head>
    <body>

    <?php
    echo "You had selected ".count($selcolour)." colours. They are :<br/>";
    foreach ($selcolour as $c=>$col)
    {
    echo $col;
    }
    ?>

    </body>
    </html>
    nvd

  2. #2
    Tiger Shark
    Join Date
    Jul 2002
    Location
    Caerphilly, Wales
    Posts
    654
    Replace the <?php ... ?> block in the 2nd file with:

    Code:
    <?php
     echo "You had selected ".count($_GET['selcolour'])." colours. They are :<ul>";
      foreach ($_GET['selcolour'] as $col) {
       echo "<li>$col</li>";
      }
     echo "</ul>";
    ?>
    You can check my version at: http://www.craigharris.co.uk/Tempora...lectColour.php

  3. #3
    Goldfish nvd80's Avatar
    Join Date
    Jul 2004
    Location
    Sabah, Malaysia
    Posts
    85
    that really clear up the problem. thx alot man!
    nvd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •