Quote:
> Thanks Justin and Stephan,
> Justin's solution worked for me. I had to make on minor modification
> in case
> anyone cares:
> $varname = "item".$cnt;
> and that did the trick.
> Thanks for your help.
> Craig
> >>Hi,
> >>I suspect this is a very simple question, but I can't seem to get the
> >>following code to work. I am trying to process a list of checkboxes.
> >>Since they are dynamically generated I've had to give them dynamically
> >>generated names on the form. In the code I am using to process the form
> >>I have the following:
> >> for($cnt = 0; $cnt < $num_items; $cnt++ )
> >>{
> >> if ( !(empty (eval("return $item'.$cnt.';") ) ) ) //var
> >return $item'.$cnt.';
> >is your problem, you have ' marks in invalid places.
> >try something along the lines of:
> >$varname=$item.$cnt;
> >if(isset($$varname) && !empty($$varname))
> >>names
> >>are $item1, $item2 ..
> >> {
> >> echo "Item ".$cnt." has been checked.";
> >> }
> >> }
> >>This produces the following error (the if statement is line 46)
> >>Parse error: parse error, unexpected T_EVAL, expecting T_VARIABLE or '$'
> >>in p:\test_apache\admin_proc_assign_reviews.php on line 46
> >>If anyone can see the problem I would greatly appreciate your help.
> >>Also, is there a PHP FAQ somewhere, if so I suspect this type of
> >>question might already be on it?
> >did you try http://www.php.net/ or
> http://www.php.net/manual/en/faq.php yet?
Oh, now I see what you are doing... you could have used
eval("return 'item'.$cnt.;") as well.
However, it would be easier to setup the HTML form to use arrays to
pass. For instance:
<input type="checkbox" name="item[0]" value="1">
<input type="checkbox" name="item[1]" value="1">
<input type="checkbox" name="item[2]" value="1">
<input type="checkbox" name="item[3]" value="1">
<input type="checkbox" name="item[4]" value="1">
<input type="checkbox" name="item[5]" value="1">
Then use something like:
foreach($_POST['item'] as $item_number=>$value){
if(!empty($value))
echo 'item #'.$item_number.' has been checked.<br>'."\n";
Quote:
}
This is the way that I usually handle it.
--
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.