$_GET and isset issues
Posted: Fri Jul 03, 2009 9:15 am
I'm having a small issue with a website I'm coding. It uses $_GET to find the content for the page that's supposed to be displaying. For example, if the URL is http://www.mysite.com?content=index, it would search the database, find the content for index, and display it. This is all working fine.
However, when a user first visits a page, it doesn't have a $_GET variable, since the URL is just the standard domain. To solve this, I made some default page content (which matched the index text), set it as a variable in config.php, and displayed that if there was no value set.
The specific code is
and
And a few SQL queries to find the data in the database. If the data doesn't exist, it doesn't set the content variable, and therefore displays the default page.
However, I'd like to have a 404 page. The problem with this is, the variable isn't defined if the database record doesn't exist, but it doesn't exist the first time that the user enters the page either.
I've tried doing an else clause on the $_GET['content'] isset in the first code snippet, but keep getting a syntax error, unexpected T_ELSE. If this works, I could use a mysql_num_rows to determine whether the page exists, and if it does show it, if not show a 404. Since the isset doesn't work, it would display the same as if the user just went to the first page though.
Any ideas? =3
Thanks
However, when a user first visits a page, it doesn't have a $_GET variable, since the URL is just the standard domain. To solve this, I made some default page content (which matched the index text), set it as a variable in config.php, and displayed that if there was no value set.
The specific code is
Code: Select all
if (isset($_GET['content'])); { //fetches information for content from url
$page = $_GET['content'];Code: Select all
if (isset($content)) { //Actual article content, place in page as appropriate
echo $content;}
else {
echo $defaultcontent; }However, I'd like to have a 404 page. The problem with this is, the variable isn't defined if the database record doesn't exist, but it doesn't exist the first time that the user enters the page either.
I've tried doing an else clause on the $_GET['content'] isset in the first code snippet, but keep getting a syntax error, unexpected T_ELSE. If this works, I could use a mysql_num_rows to determine whether the page exists, and if it does show it, if not show a 404. Since the isset doesn't work, it would display the same as if the user just went to the first page though.
Any ideas? =3
Thanks