Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php variable passing issue

Options
  • 01-07-2005 2:21pm
    #1
    Closed Accounts Posts: 975 ✭✭✭


    I've got a new install of php 5.0.4 running with IIS6 on win 2003 server. register_globals is off. Variables are not getting out of my form. Even with a simple exampl I snagged off the net (see below) I get

    "Notice: Undefined index: Number in c:\Inetpub\wwwroot\admin\test.php on line 2
    The number is
    >"

    Any ideas?
    Thanks.

    > Script name : test.php <

    <?php
    echo "The number is
    >" . $_POST;
    ?>
    > Script Ends <

    > Script name : form.php <

    <?php
    echo "<form method=POST action=\"./test.php\">
    <input type=text name=Number size=20>  <input type=submit value=\"Submit\"></form>";
    ?>
    > Script Ends <


Comments

  • Registered Users Posts: 2,157 ✭✭✭Serbian


    Hrm, try this as your whole PHP page:

    [php]<?php

    if ( $_SERVER == "POST" )
    {
    echo "The number is
    >" . $_POST;
    }

    echo "<form method=\"POST\" action=\"test.php\">
    <input type=\"text\" name=\"Number\" size=\"20\">
      <input type=\"submit\" value=\"Submit\">
    </form>";
    ?>
    [/php]

    You could also try print_r ( $_POST ); to debug.


  • Closed Accounts Posts: 975 ✭✭✭squibs


    Serbian,
    I tried your script - same result: undefined index
    I the added print_r ( $_POST ); to the bottom of the script.

    It gives Array ()

    :eek:


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Try stick in

    [PHP]foreach($_POST as $key => $val) print("$key => $val<br>");[/php]
    This line always comes in really handy for me when troubleshooting.


  • Closed Accounts Posts: 975 ✭✭✭squibs


    That foreach statement outputs nothing, unfortunately. I'm now suspecting my php install. I didn't mess with php.ini much though....


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Actually I never looked at your form code.

    To satisfy my curiosity, try replacing
    <input type=text name=Number size=20>

    with

    <input type=\"text\" name=\"Number\" size=\"20\">


  • Advertisement
  • Registered Users Posts: 2,157 ✭✭✭Serbian


    seamus wrote:
    Try stick in

    [PHP]foreach($_POST as $key => $val) print("$key => $val<br>");[/php]
    This line always comes in really handy for me when troubleshooting.

    print_r does essentially the same thing, you just can't do custom formatting with it.

    It's an odd one alright. Reinstallation of PHP might be an idea alright, are you on a windows or Unix machine?


  • Closed Accounts Posts: 975 ✭✭✭squibs


    Seamus - I'm at home now ( it's a problem on a machine at work) so I'll try that on Monday and let you know. Thanks!

    Serbian it's a windows machine.


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    Your form is USING POST, right? You might want to try using $_REQUEST instead of $_POST, btw; it contains data from GET, POST and cookies.


  • Registered Users Posts: 5,335 ✭✭✭Cake Fiend


    Your script looks ok, but I've always had trouble with PHP on IIS. Have you tried Apache?
    Also, out of curiosity, try turning on register_globals and see if a global var works.
    Presumably regular variables work ok?


  • Closed Accounts Posts: 975 ✭✭✭squibs


    rsynnott - that worked. Thank you :):):)

    I still don't understand why $_POST would pull data from method="post".
    Out of curiosity, can you suggest why? A vagary of IIS.

    Sico, I'll be running multiple sites (throught different ports) off this server, and I'll also be serving ASP pages. I'm not comfortable attempting that with apache. Thanks for the help though.


  • Advertisement
  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    squibs wrote:
    rsynnott - that worked. Thank you :):):)

    I still don't understand why $_POST would pull data from method="post".
    Out of curiosity, can you suggest why? A vagary of IIS.

    No, it's standard. $_GET is populated with GET requests, $_POST is populated with POST requests, $_COOKIES is populated with cookies, $_REQUEST is populated with all three. I think the original reasoning was to stop people trivially overriding cookies.


  • Closed Accounts Posts: 975 ✭✭✭squibs


    That should have read "I still don't understand why $_POST WOULDN'T pull data from method="post". I get that REQUEST does all three, but if that works, surely POST wouldtoo, assuming method was post?


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    Yes, it would, if method WAS post


  • Closed Accounts Posts: 975 ✭✭✭squibs


    But it didn't :)
    Using $_POST and method post I got not a sausage. I just switched to $_request, leaving method="post" and the data came thru.No other changes - weird.


Advertisement