Well, my code worked fine with that one simple change from "=" to "=="


> -----Original Message-----
> From: Richard Lynch [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, November 29, 2006 13:47
> To: [EMAIL PROTECTED]
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Maybe an HTML prob?
> 
> On Wed, November 29, 2006 12:52 pm, Frank Reichenbacher, Bio-Concepts,
> Inc. wrote:
> > $Permission = $_POST["Permission"];
> > if ($Permission = "Yes") {
> 
> In addition to the aforementioned = versus == error, your code will
> generate an E_NOTICE for an unchecked "Permission" box.
> 
> HTML/HTTP simply does not transmit anything at all for unchecked boxes.


Which is why my code worked. If $Permission is not "Yes" then $Permission
evaluates to "No". I did understand that the HTML wouldn't transmit anything
for an unchecked checkbox. That is what I was counting on. I was expecting
that $Permission would have been "empty" (or is it not isset?).

Frank


> 
> A better expression might be:
> $Permission = isset($_POST['Permission']) ? "yes" : "no";
> 
> The actual value sent by a single checkbox is rarely of any use.
> 
> But when you have a whole array of them, it can be very useful indeed.
> 
> E.g.;
> 
> <input type="checkbox" name="Permission[newsletter]" value="7" />
> <input type="checkbox" name="Permission[coupons]" value="5" />
> ..
> ..
> ..
> <?php
> //list of all possible permissions:
> $Permissions = array('newsletter', 'coupons', 'share_email');
> $Permission = isset($_POST['Permission']) ? $_POST['Permission'] :
> array();
> $granted = array();
> foreach($Permissions as $p){
>   if (isset($Permission[$p])) $granted[$p] = $Permission[$p];
> }
> var_dump($granted);
> ?>
> 
> In this not-so-great example, not only do we have the index of the
> array for the Permission, but also the value -- which doesn't have
> much meaning in this context.
> 
> But with an N-to-N relationship in SQL, the multiple checkbox as an
> array can often provide a very nice pattern for relating:
> table1 <-> cross-table <-> table2
> where the checkboxes indicate which rows exist in 'cross-table' for
> any given ID in table1, to relate them N-to-N to all the IDs in the
> checkbox values for table2.
> 
> This is an idiom where PHP performs like a thoroughbred, while most
> other web application languages look like total nags.
> 
> YMMV
> 
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some starving artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to