SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot dragonfly7's Avatar
    Join Date
    May 2003
    Location
    ontario
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Register Globals off - need to revise code

    We have transfered a site to a new server and the register globals is off. We need to revise the code to pass information from one page to the next.

    The first file is a form with 3 search fields.

    The second file (processing file) checks to see if all fields are empty. If all three are empty it is supposed to pass the variable $error=1 in the url so that the user is sent to the phone.php page and prompted to enter data and resubmit.

    We can't use a PHP_SELF form in this case.

    This is the code at the top of the processing page that checks for empty fields and directs the user to the phone.php page if the fields are empty:
    PHP Code:
    <?php
    // if the user didn't specify a value in all three fields, then send the user back
    if (($lastname == "") && ($site == "selectsite") && ($dept == "selectdept"))
    {
    header("Location: http://www.website.com/phone.php?error=1");
    exit;
    }
    ?>
    Then on the phone.php page it looks to see if $error=1 and if so displays a message in red to the user:
    PHP Code:
    if ($error == 1)
    {
    echo 
    "<tr><td><p><span style='color: red'>Please enter search terms & try again.
    </span></p></td></tr>"
    ;

    The user is being sent back to the phone.php page but it is not recognizing that error=1 and therefore not displaying the message.

    Any suggestions? Thank you.

  2. #2
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dragonfly7
    We have transfered a site to a new server and the register globals is off. We need to revise the code to pass information from one page to the next.

    The first file is a form with 3 search fields.

    The second file (processing file) checks to see if all fields are empty. If all three are empty it is supposed to pass the variable $error=1 in the url so that the user is sent to the phone.php page and prompted to enter data and resubmit.

    We can't use a PHP_SELF form in this case.

    This is the code at the top of the processing page that checks for empty fields and directs the user to the phone.php page if the fields are empty:
    PHP Code:
    <?php
    // if the user didn't specify a value in all three fields, then send the user back
    if (($lastname == "") && ($site == "selectsite") && ($dept == "selectdept"))
    {
    header("Location: http://www.website.com/phone.php?error=1");
    exit;
    }
    ?>
    Then on the phone.php page it looks to see if $error=1 and if so displays a message in red to the user:
    PHP Code:
    if ($error == 1)
    {
    echo 
    "<tr><td><p><span style='color: red'>Please enter search terms & try again.
    </span></p></td></tr>"
    ;

    The user is being sent back to the phone.php page but it is not recognizing that error=1 and therefore not displaying the message.

    Any suggestions? Thank you.
    For posting use $_POST for variables in the url use $_GET. So if error is in the url then you can access it by:

    $_GET['error']

    and since it is a number make sure it is passed as a number:

    intval($_GET['error'])

    Silly

  3. #3
    SitePoint Zealot dragonfly7's Avatar
    Join Date
    May 2003
    Location
    ontario
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank-you!! It worked.


Bookmarks

Posting Permissions

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