This is the code I use:
<?php
$display_title = mysql_query("SELECT pagetitle FROM legal WHERE pageid=$pageid")
or die ("MySQL Error - Please report this to the webmaster");
if ($pageid < 1 OR $pageid >6)
{
echo("No Such Page");
}
else
{
while ($row = mysql_fetch_array($display_title))
{
$legal = $row["pagetitle"];
echo $legal;
}
}
?>
This code is used on a page, legal.php to show legal notices (privacy policy, terms of use, etc.). In the database where the legal notices are stored, there are only 6 pageid's (1-6), so you can see that if the page id is less than one, it displays an error message, if it is more than 6 it displays an error message.
This is all dandy for legal.php, but what about a database that is always getting new data, more and more pageid's, it would be a pain in the neck to keep changing the IF statement all the time, and would soon be confusing. What I am trying to accomplish is this: I want the page to check the database to see if the pageid that is in the url (ex: http://domain.com/page.php?pageid=21) exists in the database. If it does not, it displays the error, if it does contain the pageid, then it continues on with the rest of the code. I hope I am not being to confusing.