Submit won't pass parameters

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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!

Re: Submit won't pass parameters (HH) wrote in

Quoted text here. Click to load it

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.

Re: Submit won't pass parameters

HH wrote:
Quoted text here. Click to load it

Probably because register_globals 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.


Re: Submit won't pass parameters

Quoted text here. Click to load it

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

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.

include "header.php";

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

<table border=0>

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_array($result))
    print "<tr><td colspan=2>$nbsp;</td></tr>\n";



<?php nav($offset);

include "end_page.php";

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_script)) {$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("select count(*) from guestbook");
    list($total_rows) = mysql_fetch_array($result);

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

    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_script?offset=".($offset+$limit)."\">Next

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!

Re: Submit won't pass parameters

HH wrote:
Quoted text here. Click to load it

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.


Re: Submit won't pass parameters

Quoted text here. Click to load it

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.php, 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!

Application: Guestbook2K
Name: authenticate.php
Purpose: Validate user name and password against the database,
using HTTP authentication.

This code uses the authenticate() function, declared in


// 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
// button in the pop-up
$realm = "Guest Book Administration";
$errmsg = "You must enter a valid name & password to access this

// 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
// authentication header has ever been sent, these variables will be

if (empty($PHP_AUTH_USER))
    // first time through - use authenticate() to request a
    // user name & password
    $query = "select username from guestbook_admin
        where password = password(lower('$PHP_AUTH_PW'))
            and username = lower('$PHP_AUTH_USER')
    $result = safe_query($query);
    if ($result) { list($valid_user) = mysql_fetch_row($result); }

    // if the query didn't work at all (which shouldn't happen), or ran
    // 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_user))
print "<p><b>Editing as $PHP_AUTH_USER</b></p>\n";

Re: Submit won't pass parameters

HH wrote:

Quoted text here. Click to load it

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:

But it would be easier to write:



Site Timeline