Jump to content


Photo

help with form using php


  • Please log in to reply
4 replies to this topic

#1 bagnallc

bagnallc
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 June 2006 - 08:39 PM

Hi all,

i am trying to process a simple checkbox form within a while statement.
form works fine but im having trouble naming the range so that selections can be retrieved

code is

while($checkbox = mysql_fetch_array($qry))
{
echo "<input type='checkbox' name='$checkbox[field]'>" . " " . $checkbox[going] . "<br/>" ;
}

when i try and retrieve name value in page where form sends information i am having problems.

can you suggest how to name each checkbox - there could be any number of checkboxes from 1 to 500?

many thanks.

#2 klaroen

klaroen
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 17 June 2006 - 08:59 PM

don't realy understand the request :P

but:
shouldn't it be
$checkbox['field'] and $checkbox['going'] with the '' signs?

I guess so...

#3 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 17 June 2006 - 09:05 PM

Normally you'd use name='blah[]' and then retrieve it using $_REQUEST['blah'] but since you're using a query, I would assume that's not what you want. My first suggestion would be to use _ instead of a space as a separator between your field and going values as that some values may have a tailing or leading space, causing problems when you try and explode() the values (of course, they might have trailing or leading underscores in which case use something silly like ===?^$;===). Also, checkboxes that have been checked will send as data but unchecked checkboxes will not send instead of having the value of false which would be expected. If you didn't know about this behaviour then that may be your problem.
[table]



Don't worry, the printer fairies will sort it out.

#4 bagnallc

bagnallc
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 June 2006 - 09:28 PM

managed to fix this now. many thanks for all your help

sorry for stupid question

#5 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 17 June 2006 - 09:29 PM

echo "<input type='checkbox' name='check[]' value='" . (isset($checkbox['field']) ? $checkbox['field'] : $checkbox['going']) . "' />";

[table]



Don't worry, the printer fairies will sort it out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users