...

View Full Version : variable variables



mathewvp
10-06-2003, 05:10 PM
Hi,
I am migrating from an older php version which is causing me a lot of problems.
I have a question answer form where the admin can enter five questions and 4 answers each and a radio group for each question for selecting the correct answer
For eg
Question1-textbox for question
Choice1 -text box with name choice1
Choice2 -text box with name choice2
Choice3 -text box with name choice3
Choice4 -text box with name choice4
Choice5 -text box with name choice5


Select the correct answer-radio box with name answer1 and these values
1)choice1 2)choice2 3)choice3 4)choice4 5)choice5

And once the form is submitted,I could find the answer that the admin selected using

$ans1=${$answer1};
and similarly for the answers for remaining questions

Now this doesn't work with newer version of php.So can anybody tell me how to solve this.

Thanks

Acecool
10-06-2003, 10:03 PM
$$answer1

mathewvp
10-07-2003, 11:05 AM
Acecool is that supposed to be an answer.Thanks anyway

mordred
10-07-2003, 12:47 PM
Looks like you're not using the newer superglobal arrays $_POST, $_GET etc. which replaced the old way of having the variables automagically put into the script by enabling register_globals since PHP 4.2. You have to rewrite your script or enable register_globals. I'll recommend the first option.

BTW, "doesn't work" is very little information to begin with. Any error messages? What does var_dump($answer1); say?

mathewvp
10-07-2003, 01:00 PM
modred, I know it doesn't work coz in newer versions of php register globals are off.I cant turn it on coz its not my server so I cant edit the php.ini file.Anyway I found a solution

Use extract() function.That will help me not to rewrite the code.Thanks for trying to help modred

mordred
10-07-2003, 02:32 PM
FYI: Another possibility would have been to use import_request_variables() for a quick and hacky fix of your problem.

mathewvp
10-07-2003, 03:17 PM
with import_request_variables() I will have to rename all my variables and the "variable variables" code will not work.And renaming all my code is a very tedeous work and error prone too. extract() does what I want for me.
Thanks modred
:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum