Submit won't pass parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HH

    Submit won't pass parameters

    I'm learning to design web applications with php, mysql, and apache
    from a book. I copied a sample application called guestbook 2000 that
    came with the CD in the book to my htdocs folder, but couldn't get the
    sign guestbook page (sign.php) to work. This page first checks the
    value of the $submit variable. If it is not "Sign", the page displays
    a blank form for the guest to sign. If it is "Sign", the page process
    the form information and sends it to a database. Everytime I click the
    submit button, the blank form reloads itself. Through testing, I found
    out that the $submit variable was never set to "Sign" when I clicked
    the button. I use IE on Windows 2000 server. Anyone who has any idea
    how to fix this problem? Thanks!
  • Theo

    #2
    Re: Submit won't pass parameters

    hhbayarea@yahoo .com (HH) wrote in
    news:3dc8787a.0 411062256.651d5 1dc@posting.goo gle.com:
    [color=blue]
    > I'm learning to design web applications with php, mysql, and apache
    > from a book. I copied a sample application called guestbook 2000 that
    > came with the CD in the book to my htdocs folder, but couldn't get the
    > sign guestbook page (sign.php) to work. This page first checks the
    > value of the $submit variable. If it is not "Sign", the page displays
    > a blank form for the guest to sign. If it is "Sign", the page process
    > the form information and sends it to a database. Everytime I click the
    > submit button, the blank form reloads itself. Through testing, I found
    > out that the $submit variable was never set to "Sign" when I clicked
    > the button. I use IE on Windows 2000 server. Anyone who has any idea
    > how to fix this problem? Thanks!
    >[/color]

    quickie since its so late and my eyes are losing focus, I assume you are
    using POST to retrive the value. when you click the submit button, which
    form object contains 'sign' as the value? otherwise, its hard to tell the
    problem without seeing any code.

    Comment

    • Bent Stigsen

      #3
      Re: Submit won't pass parameters

      HH wrote:[color=blue]
      > I'm learning to design web applications with php, mysql, and apache
      > from a book. I copied a sample application called guestbook 2000 that
      > came with the CD in the book to my htdocs folder, but couldn't get the
      > sign guestbook page (sign.php) to work. This page first checks the
      > value of the $submit variable. If it is not "Sign", the page displays
      > a blank form for the guest to sign. If it is "Sign", the page process
      > the form information and sends it to a database. Everytime I click the
      > submit button, the blank form reloads itself. Through testing, I found
      > out that the $submit variable was never set to "Sign" when I clicked
      > the button. I use IE on Windows 2000 server. Anyone who has any idea
      > how to fix this problem? Thanks![/color]

      Probably because register_global s is set to off.

      In that case you can either replace all the request variables with their
      'superglobal' counterparts. (i.e. $_POST['submit'] instead of $submit),
      or use import_request_ variables("gp") in the beginning of the script.

      About the superglobals:..


      If it doesn't do the trick, them post the code.

      /Bent

      Comment

      • HH

        #4
        Re: Submit won't pass parameters

        Bent Stigsen <ngap@thevoid.d k> wrote in message news:<418dd2c0$ 0$69072$edfadb0 f@dread15.news. tele.dk>...[color=blue]
        > HH wrote:[color=green]
        > > I'm learning to design web applications with php, mysql, and apache
        > > from a book. I copied a sample application called guestbook 2000 that
        > > came with the CD in the book to my htdocs folder, but couldn't get the
        > > sign guestbook page (sign.php) to work. This page first checks the
        > > value of the $submit variable. If it is not "Sign", the page displays
        > > a blank form for the guest to sign. If it is "Sign", the page process
        > > the form information and sends it to a database. Everytime I click the
        > > submit button, the blank form reloads itself. Through testing, I found
        > > out that the $submit variable was never set to "Sign" when I clicked
        > > the button. I use IE on Windows 2000 server. Anyone who has any idea
        > > how to fix this problem? Thanks![/color]
        >
        > Probably because register_global s is set to off.
        >
        > In that case you can either replace all the request variables with their
        > 'superglobal' counterparts. (i.e. $_POST['submit'] instead of $submit),
        > or use import_request_ variables("gp") in the beginning of the script.
        >
        > About the superglobals:..
        > http://www.php.net/manual/en/languag...predefined.php
        >
        > If it doesn't do the trick, them post the code.
        >
        > /Bent[/color]

        Bent, thanks for the superglobal idea! The page sign.php finally
        worked. But a new problem came

        up with the view.php page. This page prints out 2 guestbook database
        records at a time with

        navigation buttons at the bottom to move back and forth from page to
        page. I was able to load the

        first two records. Then when I press the Next Entries link at the
        bottom, the same first two

        records load again. Through debugging, I noticed that although the url
        in the address window

        showed:

        the actual value of the variable offset, which was passed through the
        link, is still 0. And I'm

        not sure how to use superglobals here.

        Here are the codes for view.php. Here, nav() is a function defined in
        header.php, and the function's codes are listed below.

        <?php
        include "header.php ";

        $page_title = "View My Guest Book!!";
        include "start_page.php ";
        ?>

        <table border=0>

        <?php
        if (empty($offset) ) { $offset = 0; }

        $preserve = "";

        // select_entries( ) (declared in header.php) should return a mysql
        // result set identifier

        $result = select_entries( $offset);
        while ($row = mysql_fetch_arr ay($result))
        {
        print_entry($ro w,$preserve,"na me","location", "email","URL"," entry
        date","comments ");
        print "<tr><td colspan=2>$nbsp ;</td></tr>\n";
        }

        mysql_free_resu lt($result);
        ?>

        </table>

        <?php nav($offset);

        include "end_page.p hp";
        ?>

        Here are the codes for function nav(). Variable $limit is set to 2 (2
        records per page):

        function nav($offset=0, $this_script="" )
        {
        global $limit;
        global $PHP_SELF;

        if (empty($this_sc ript)) {$this_script = $PHP_SELF;}
        if (empty($offset) ) { $offset = 0; }

        // get the total number of entries in the guest book -
        //we need this to know if we can go forward from where we are
        $result = safe_query("sel ect count(*) from guestbook");
        list($total_row s) = mysql_fetch_arr ay($result);

        if ($offset > 0)
        {
        // if we're not on the first record, we can always go backwards
        print "<a href=\"$this_sc ript?offset=".( $offset-$limit)."\">Pre vious

        Entires</a>";
        }
        if ($offset+$limit < $total_rows)
        {
        // offset + limit gives us the maximum record number
        // that we could have displayed on this page. If it's
        // less than the total number of entries, that means
        // there are more entries to see, and we can go forward
        print "<a href=\"$this_sc ript?offset=".( $offset+$limit) ."\">Next
        Entries</a>";
        }
        }
        ?>

        I'm not sure how to use superglobals here. I tried to use
        $_GET('offset') at a few places, but I kept getting error messages
        when I display the page. Could you help? Thanks again!
        HH

        Comment

        • Bent Stigsen

          #5
          Re: Submit won't pass parameters

          HH wrote:
          [snip][color=blue]
          > I'm not sure how to use superglobals here. I tried to use
          > $_GET('offset') at a few places, but I kept getting error messages
          > when I display the page. Could you help? Thanks again![/color]

          I assume you did use $_GET['offset'] and not $_GET('offset')

          You can either use the "import_request _variables" function if you not
          sure what other parameters might exist or use
          $offset = $_GET['offset']; in the beginning the the scripts.

          /Bent


          Comment

          • HH

            #6
            Re: Submit won't pass parameters

            Bent Stigsen <ngap@thevoid.d k> wrote in message news:<41943b31$ 0$75222$edfadb0 f@dread15.news. tele.dk>...[color=blue]
            > HH wrote:
            > [snip][color=green]
            > > I'm not sure how to use superglobals here. I tried to use
            > > $_GET('offset') at a few places, but I kept getting error messages
            > > when I display the page. Could you help? Thanks again![/color]
            >
            > I assume you did use $_GET['offset'] and not $_GET('offset')
            >
            > You can either use the "import_request _variables" function if you not
            > sure what other parameters might exist or use
            > $offset = $_GET['offset']; in the beginning the the scripts.
            >
            > /Bent[/color]

            It worked after I changed $_GET('offset') to $_GET['offset']. I'm
            still new to php. Won't make that mistake again. Now I have trouble
            with edit.php page, which when first clicked, it asks for a username
            and password, and if validation is successful, I'll arrive at a page
            that allows me to delete unwanted entries in the database. I'm pretty
            sure I used the correct username and password. But it just won't let
            me pass through. Below is authenticate.ph p, which is included at the
            beginning of edit.php and responsible for the authentication part. I
            even used globals here, but it gives me three times to try, and ends
            with the display of $errmsg. Any ideas? Thanks so much for the help!
            HH

            <?php
            /*
            Application: Guestbook2K
            Name: authenticate.ph p
            Purpose: Validate user name and password against the database,
            using HTTP authentication.

            This code uses the authenticate() function, declared in
            /book/functions/basic.php.

            */


            // realm is the label that will appear in the pop-up window that
            // asks for name and password.
            // errmsg is the text that will be displayed if the user hits the
            'Cancel'
            // button in the pop-up
            $realm = "Guest Book Administration" ;
            $errmsg = "You must enter a valid name & password to access this
            function";

            // PHP_AUTH_USER and PHP_AUTH_PW are global variables supplied by
            // PHP, corresponding to the user name & password the user has entered
            // in the pop-up window created by an HTTP authentication header. If
            no
            // authentication header has ever been sent, these variables will be
            empty.

            $PHP_AUTH_USER = $GLOBALS['PHP_AUTH_USER'];
            $PHP_AUTH_PW = $GLOBALS['PHP_AUTH_PW'];
            if (empty($PHP_AUT H_USER))
            {
            // first time through - use authenticate() to request a
            // user name & password
            authenticate($r ealm,$errmsg,"h eader");
            }
            else
            {
            $query = "select username from guestbook_admin
            where password = password(lower( '$PHP_AUTH_PW') )
            and username = lower('$PHP_AUT H_USER')
            ";
            $result = safe_query($que ry);
            if ($result) { list($valid_use r) = mysql_fetch_row ($result); }

            // if the query didn't work at all (which shouldn't happen), or ran
            but
            // didn't find a match for the user name & password, $valid_user will
            // not be set to anything. if this is so, have the user try again.
            if (!$result || empty($valid_us er))
            {
            authenticate($r ealm,$errmsg,"q uery");
            }
            }
            print "<p><b>Edit ing as $PHP_AUTH_USER</b></p>\n";
            ?>

            Comment

            • Bent Stigsen

              #7
              Re: Submit won't pass parameters

              HH wrote:
              [snip]
              [color=blue]
              > $PHP_AUTH_USER = $GLOBALS['PHP_AUTH_USER'];
              > $PHP_AUTH_PW = $GLOBALS['PHP_AUTH_PW'];[/color]

              PHP_AUTH_USER and PHP_AUTH_PW would be defined in the $_SERVER variable,
              so to access it through $GLOBALS you would have to write:
              $GLOBALS['_SERVER']['PHP_AUTH_USER']

              But it would be easier to write:

              $PHP_AUTH_USER = $_SERVER['PHP_AUTH_USER'];
              $PHP_AUTH_PW = $_SERVER['PHP_AUTH_PW'];

              /Bent


              Comment

              Working...