Results 1 to 5 of 5
Thread: PHP/mySQL problem
-
05-16-2005, 01:59 PM #1Junior Guru Wannabe
- 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", USERNAME, PASSWORD) 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
?>
Does anyone know what may be wrong here?
-
05-16-2005, 05:17 PM #2Living the dream
- 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'];
SELECT * FROM Page WHERE Path='$REQUEST_URI'
replacing $REQUEST_URI with what it should be, do some test..
Regards
-
05-16-2005, 05:57 PM #3Web Hosting Master
- 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", USERNAME, PASSWORD) 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);
?>Testing 1.. Testing 1..2.. Testing 1..2..3...
-
05-17-2005, 08:24 PM #4Junior Guru Wannabe
- 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?
-
05-17-2005, 09:03 PM #5Web Hosting Master
- 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