Click to See Complete Forum and Search --> : what's wrong with my php coding?


nvd80
08-14-2005, 01:07 PM
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>

Bothware
08-14-2005, 08:51 PM
Replace the <?php ... ?> block in the 2nd file with:


<?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/TemporaryTesting/SelectColour.php

nvd80
08-15-2005, 05:22 AM
that really clear up the problem. thx alot man!