Re: Variable variable

From: Date: Wed, 18 Apr 2001 11:21:27 +0000
Subject: Re: Variable variable
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49175@lists.php.net to get a copy of this message
Your problem has little to do with the things mentioned. First of all, you are refering to a variable variable incorrectly. You must use brackets, like this: ${$id} If ID has the value "Blue", then the above is the same as: $Blue So in your examble if you had the checkbox with the value "on", and you want to see if it was checked, use this: if (${$id} == "on") { echo 'on'; } else { echo 'off'; } But that's an overly complicated way of doing it if you know the "name" of the checkbox. If the name of the checkbox is "id", then use this piece of code to access it if it was submitted via POST or GET (which works even if register_globals is turned off): $f = 'HTTP_' . $HTTP_ENV_VARS["REQUEST_METHOD"] . '_VARS'; if (${$f}["id"] == "on") { echo 'The checkbox with the name "id" has the value "on"'; } else { echo "The checkbox with the name "id" was not selected"; } But if register globals was on, all you have to use is: if ($id == "on") { echo 'The checkbox with the name "id" has the value "on"'; } else { echo "The checkbox with the name "id" was not selected"; } Tell me if that doesn't answer your questions. -- Plutarck Should be working on something... ...but forgot what it was. ""Jacky"" <jacky@activelifestyle.com> wrote in message news:011001c0c839$ebfb9b40$6400a8c0@activelifestyle.com... Hi all I have a form with check box and name of those checkboxes is usuing variable lke this, <!-- I got the value $id from a table and looping them and assign them to the check box name--> <input type="checkbox" name ="$id" value="on"> and when I submit the form to page foo.php4, at that page, I use Variable variable to call the value of the check box to see if it checked like this $quey = "select id from table"; $result = ...... ( assumeing it is done and i got value for $id for all records from table) if ($$id =="on"){ echo "on"; }else{ echo "off"; } It always returns echo "off", why is that? cheers Jack jacky@activelifestyle.com "There is nothing more rewarding than reaching the goal you set for yourself"

« previous php.general (#49175) next »