Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    variable variables

    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

  • #2
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $$answer1

  • #3
    New Coder
    Join Date
    Jul 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Acecool is that supposed to be an answer.Thanks anyway

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    De gustibus non est disputandum.

  • #5
    New Coder
    Join Date
    Jul 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    FYI: Another possibility would have been to use import_request_variables() for a quick and hacky fix of your problem.
    De gustibus non est disputandum.

  • #7
    New Coder
    Join Date
    Jul 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •