bertieboy_93 Posted August 13, 2006 Share Posted August 13, 2006 Hi. I'm a newbie to these forums and to PHP, so please forgive me if the answer is something obvious.I am using a mysql database to store text which will be loaded onto my web pages. I want to use $_SERVER['PHP_SELF'] in order to identify the page that is currently open, and then match it up to the correct entry in the database. (by identifying the current page URL, and then matching that up to the URL field in the database). The problem is that I am receiving a Parse error, and it always identifies the line which contains $_SERVER['PHP_SELF'] as the culprit. The exact error is: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING...My PHP code is below.[code]<?//Define variables$username="XXX";$password="XXX";$database="XXX";$URL="$_SERVER['PHP_SELF']";//Connect to databasemysql_connect(localhost,$username,$password);@mysql_select_db($database)or die(mysql_error());//Select information from database$query = "SELECT PageHeading FROM Main WHERE PageURL=$URL";$result = mysql_query($query);if (!$result) { die('Could not query:' . mysql_error());}//Display textecho mysql_result($result,0);?>[/code]I tried manually typing in the URL rather than using $_SERVER['PHP_SELF'] but this returned the MySQL error:Could not query:Unknown column 'index.php' in 'where clause'The only thing that does work is manually typing in the Page_ID (primary key).Does anyone know a solution where I can use a script to determine the current page and then retrieve the correct entry from a MySQL database.I'd be incredibly grateful to anyone that could help. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 13, 2006 Share Posted August 13, 2006 Give this a try:[code]<?php//Define variables$username="XXX";$password="XXX";$database="XXX";$URL=$_SERVER['PHP_SELF']; // edited//Connect to databasemysql_connect(localhost,$username,$password);mysql_select_db($database)or die(mysql_error()); // edited//Select information from database$query = "SELECT PageHeading FROM Main WHERE PageURL='$URL'"; // edited$result = mysql_query($query) or die("error: ". mysql_error(). " with query ". $query); // edited/* ignore redundant codeif (!$result) {die('Could not query:' . mysql_error());}*///Display textecho mysql_result($result,0);?>[/code] Quote Link to comment Share on other sites More sharing options...
bertieboy_93 Posted August 13, 2006 Author Share Posted August 13, 2006 Great! That worked perfectly. It looks like there was quite a lot wrong with my code! I haven't got much knowledge of PHP or MySQL, I've just been following through numorous online tutorials. Thanks for such a speedy response, your help has been very valuable to me.Thanks again.Rob. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.