Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    42

    PHP/mySQL problem

    I use the following code to retrieve a URI from a database:
    PHP Code:
    <?php
    //get the entry for the page
    $dbh=mysql_connect ("localhost"USERNAMEPASSWORD) or die ('I cannot connect to the database because: ' mysql_error());
    mysql_select_db ("onestop_index",$dbh);
    $pageEntry=mysql_query("SELECT * FROM Page WHERE Path=\'$REQUEST_URI\'");
    $pageURI=mysql_result($pageEntry,0,"URI");
    //if the requested page exists, update the values
    ?>
    it wasn't working, so I made the script echo the URI that it gets out of the database, and found that I end up with an empty string.

    Does anyone know what may be wrong here?

  2. #2
    Join Date
    May 2005
    Location
    Planet Earth
    Posts
    813
    As you are trying to retrieve the information of the first row, I would suggest trying:

    PHP Code:
     // I don't trust '$REQUEST_URI' as it could be misinterpreted as a string
     // I prefer '{$REQUEST_URI}' to be sure..
     // or maybe $_SERVER['REQUEST_URI']
     
    $pageEntry=mysql_fetch_assoc(mysql_query("SELECT * FROM Page WHERE Path='{$REQUEST_URI}'"));
     
    $pageURI=$pageEntry['URI']; 
    if it is still not working, go in your database by hand and try:

    SELECT * FROM Page WHERE Path='$REQUEST_URI'

    replacing $REQUEST_URI with what it should be, do some test..


    Regards

  3. #3
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,345

    Re: PHP/mySQL problem

    PHP Code:
    <?php
    //get the entry for the page
    $dbh=mysql_connect ("localhost"USERNAMEPASSWORD) or die ('I cannot connect to the database because: ' mysql_error());
    mysql_select_db ("onestop_index",$dbh);

    $pageEntry=mysql_query("SELECT * FROM `Page` WHERE `Path`='$REQUEST_URI'");
    $page mysql_fetch_row($pageEntry);
    //$page contains the resulting rwo
    print_r($page);
    ?>
    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  4. #4
    Join Date
    Jul 2004
    Posts
    42
    ok, i'll try the solution with the mysql_fetch_assoc

    also, might it be due to a problem with the database? Does the field have to be set to a specific type (text, varchar, etc) for it to work right?

  5. #5
    Join Date
    Mar 2004
    Posts
    1,303
    are you sure your $REQUEST_URI contains anything or empty

    try to use: $_SERVER['REQUEST_URI'];

    echo $_SERVER['REQUEST_URI'];
    and
    echo $REQUEST_URI;

    to see which one works.

    your code might be old

Posting Permissions

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