SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strange PHP/MySQL Problem

    Hi all,

    I recently moved my website to another server which has a different PHP version, I think.

    On the old server, I could retrieve data from my database with no problem. But now I'm having problems although I didn't change anything in my scripts.

    The script retrieve a tutorial from a database.

    # tutorial number one's URL is
    mydomain.com/tutor.php?tid=1

    # tutorial number two's URL is
    mydomain.com/tutor.php?tid=2

    And so on..

    Here is the tutor.php script:

    PHP Code:
    <?
    session_start
    ();
    if (!isset(
    $tid)) {
    die(
    'An error has ocurred. The ID could not be retrieved.');
    exit();
    }

    include 
    'db.php';

    $sql mysql_query("SELECT * FROM tutorials WHERE tid='$tid'");
    $lookup mysql_fetch_assoc($sql);
    $tut $lookup['tutorialtext'];
    $author $lookup['Author'];
    $date $lookup['date'];
    $title $lookup['tutorialtitle'];
    ?>
    And then, within the body of my webpage, I make the call to "$tut" to show the text of the tutorial.

    The above worked on the old server OK. But now that I moved to another server which uses PHP 4.2.2, I get the following error message:

    Code:
    An error has ocurred. The ID could not be retrieved.
    If you look to the above script, you will see that this error message is only displayed if the variable "tid" doesn't exist. But it DOES! Yet, I still receive this error message.

    What do you think is the problem? I appreciate any help.

    Thanks.

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    register_global is probably disabled on this host's PHP installation.

    To access parameters passed via the URL you cannot use the variable name anymore.

    You have to use: $_GET['variablename']

    Change your script to:

    PHP Code:
    <?
    session_start
    ();
    $tid $_GET['tid'];
    if (!isset(
    $tid)) {
       die(
    'An error has ocurred. The ID could not be retrieved.');
    }

    the rest of the script here
    and it should work.

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Texas, USA
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or I can just turn the register_global on, right? How do I do that? Note that it's a dedicated server, so I'm the only one on it.

    Thank you for your help.

  4. #4
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then you have to edit the php.ini and change

    register_globals = Off

    to

    register_globals = On

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Location
    United States
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's recommended to leave register_globas = Off.

    http://www.php.net/register_globals

    -J


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
  •