a php code

Scot L. Harris webid at cfl.rr.com
Mon Jul 26 18:13:55 UTC 2004


On Mon, 2004-07-26 at 13:04, Hongwei Li wrote:

> Here is my test code, called fm.php:
> 
> <?php
> if (!isset($pick)) {
>  echo "Select color(s) and submit the form below."; }
> else {
>  $j = count($pick);
>  for($i=0; $i<$j; $i++) {
>   echo "Pick <b>$pick[$i]</b> is Checked<br />"; }
>  }
> ?>
> 
> <form action="<?php echo $_SERVER['PHP_SELF']; ?>">
> <ol>
> <li>Red<input name="pick[]" type=checkbox value="Red" /></li>
> <li>Blue<input name="pick[]" type=checkbox value="Blue" /></li>
> <li>Yellow<input name="pick[]" type=checkbox value="Yellow" /></li>
> </ol>
> 
> <input type="submit" value="Submit!" />
> <input type="reset" value="Reset" />
> </form>
> 
> When I test it, the browser displays the form with "Select color(s) and
> submit the form below.", and the browser address box shows 
> http://.../fm.php
> 

pick is being used as an array in your form but I think the test is
looking at it as a regular variable which isset is most likely always
evaluating as true.

You can test if each element in the array is set isset($pick[0]) etc
but I don't think testing on the name of the array will give you what
you want.

You will need to iterate through the array testing each value.

An excellent place for info on php is http://www.php.net.  They have
have a lot of good examples and you can search for information on
various functions very easily.

-- 
Scot L. Harris
webid at cfl.rr.com

You can fool some of the people all of the time,
and all of the people some of the time,
but you can make a fool of yourself anytime. 





More information about the users mailing list