Re: [PHP] Creating Dynamic Variables
On Wed, 17 Jul 2002 22:39:10 -0400, you wrote: >Hello, I have captured variables from any HTML that is POSTed to me from a >'foreach' clause. Now, possibly in this foreach clause I want to register >these name/value pairs into a session var. I have tried : >session_start(); >foreach ($HTTP_POST_VARS as $name=>$value) { >$name=$value; >session_register(name); //without the $ >} >and get nothing. Assuming register_globals is off: session_start(); foreach ($HTTP_POST_VARS as $name => $value) { $$name = $value; session_register($name); } Remember, $name only contains the name of the variable, not a reference to the variable itself. To create a new global variable with the name "$name", you have to use a variable variable, hence $$name. Session_register, however, only requires a string which contains the name of the variable you want to register. $name will provide that by itself. In your example, by leaving off the dollar sign, you are referencing an undefined constant called "name"... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Creating Dynamic Variables
Try putting "" around name in session_register? > Hello, I have captured variables from any HTML that is POSTed to me from a > 'foreach' clause. Now, possibly in this foreach clause I want to register > these name/value pairs into a session var. I have tried : > session_start(); > foreach ($HTTP_POST_VARS as $name=>$value) { > $name=$value; > session_register(name); //without the $ > } > and get nothing. > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -Pushkar S. Pradhan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Creating Dynamic Variables
I think you're more after this session_start(); foreach ($HTTP_POST_VARS as $name=>$value) { $$name=$value; session_register($name); //with the $ } HTH Martin -Original Message- From: Anup [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 18, 2002 12:39 PM To: [EMAIL PROTECTED] Subject: [PHP] Creating Dynamic Variables Hello, I have captured variables from any HTML that is POSTed to me from a 'foreach' clause. Now, possibly in this foreach clause I want to register these name/value pairs into a session var. I have tried : session_start(); foreach ($HTTP_POST_VARS as $name=>$value) { $name=$value; session_register(name); //without the $ } and get nothing. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php