Hi,

I'm new to php....just started using php4...i'm facing a problem with variables...

Lets say i have a textbox named "Name" ->
<font class=F1><input type=text name="Name"></font>

I get a warning message "Warning: Undefined variable: Name in....." everytime i use $Name to get the value in it. But if i append @ to it.....@$Name....it works fine...is there any patch/solution to this problem??

    Yes. It depends on the PHP version. If you are using 4.0.6 or above and have register_globals = on on you php.ini file, you won't be getting this problem.

    You can always use the following arrays to reference data from forms:

    $HTTP_POST_VARS
    $HTTP_GET_VARS

    If using php 4.1.2 or above, the arrays are now named

    $POST
    $
    GET

    So, you would be using one of the three following options for your $Name variable:

    1 .- Set <B>register_globals = on</B> on your php.ini file
    2 .- Use $HTTP_POST_VARS or $HTTP_GET_VARS
    3 .- Use $POST or $GET (remember, PHP 4.1.2 or above)

    Hope this helps

    fLIPIS

      Thanks for the tip....but the problem is only partly solved. When I try to use $Name...eg valid_name($Name)....I get the same error -> Warning: undefined variable Name.....

      I don't get it....pls help!

        I'm giving you an example:

        //FIRST: THE FORM (Save this as form.html)
        <FORM NAME="TheForm" ACTION="seevars.php" METHOD="POST">
        <INPUT TYPE="TEXT" NAME="the_var">
        <INPUT TYPE="SUBMIT" VALUE="Rock it, baby">
        </FORM>

        //SECOND: THE PHP PROCESSING DATA (Save this as seevars.php)

        <?

        echo $HTTP_POST_VARS["the_var"];
        $Name = $HTTP_POST_VARS["the_var"];
        echo $Name;

        //If using PHP 4.1.2 or above, you can replace it by this (uncomment)

        //echo $POST["the_var"];
        //$Name = $
        POST["the_var"];
        //echo $Name;

        ?>

        Hope this was more helpful

        fLIPIS

          Thank you again....your script works fine...and I understand what u mean the first time around. However, my scripts action=<?=$PHP_SELF?>. I think this is causing all the trouble. Eventhough i have turn the register_globals ON....i still get the same error....even $HTTP_POST_VARS is an undefined variable...this is what i don't understand.

            What version are u using? I mean PHP version

              Check this:

              variables_order = "EGPCS"
              magic_quotes_gpc = On

              Hope it helps

              fLIPIS

                Write a Reply...