Results 1 to 5 of 5

Thread: PHP forms

  1. #1

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353

    PHP forms

    I've posted a form to a php page which works, but for some reason on my PWS Win 98 machine it won't receive the posts. Normally on php you don't have to call the form do you, just put in the name of the form object name:

    e.g. on my form:

    <INPUT TYPE='TEXT' NAME='atextbox'>



    on my posting to page.

    <?php
    echo "The information you posted was $atextbox<BR>\n";
    ?>


    It keeps telling me that $atextbox is not defined!
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    If there's no information in the box, it won't set it as a variable. But if you are putting information in it, try accessing it like so:

    PHP Code:
    <?php
        
    //if you use PHP 4.1.0 or higher:
        
    echo "The information you posted was " .  $_REQUEST['atextbox'] . "<BR>\n";

        
    //earlier version than PHP 4.1.0:
        
    echo "The information you posted was " .  $HTTP_SERVER_VARS['atextbox'] . "<BR>\n";
    ?>
    If it works the above way, it means that register_globals is off in the php ini.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Also, I believe if you are trying to access it in a function, you'll have to tag it as global like so:

    PHP Code:
    <?php
        
    if(isset($submit)) {
            
    parsedata();
        } else {
            
    showform();
        }
        
        function 
    showform() {
            
    //show our form
        
    }
        
        function 
    parsedata() {
            global 
    $donkey;
            
    //in order to print out $donkey, one of our forms
            //variables, we have to tag it as global like above
            
    echo $donkey;
        }
    ?>
    or you can do it:

    PHP Code:
    <?php
        
    if(isset($_REQUEST['submit'])) {
            
    parsedata();
        } else {
            
    showform();
        }
        
        function 
    showform() {
            
    //show our form
        
    }
        
        function 
    parsedata() {
            echo 
    $_REQUEST['donkey'];
        }
    ?>
    As the variables in $_REQUEST are superglobals, they are accessable anywhere in the script. This is also the new PHP standard.

    Let me know if any of this helps.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    is it a warning message? you have to turn that off in the php.ini file. or you can define you variables.

  5. #5

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353
    Cheers everyone I'll try your ideas tonight, and get back to you on monday to say if they work. but I'm sure they will work.

    Thanks alot.
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

Posting Permissions

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



Click Here to Expand Forum to Full Width