peter_anderson Posted August 15, 2009 Share Posted August 15, 2009 Hi all, I'm trying to create a small CMS, which gets the page from the variable at the URL (eg page.php?page=XXXX), but now I need to redirect it to 404 if the page does not exist. Here's some of my code (the rest deals with the theme, user login, etc) //get page $pg = $_GET['page']; //connect to DB mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); //query $query = mysql_query("SELECT * from `page` WHERE id='$pg'") or die(mysql_error()); // Perform Query $row = mysql_fetch_array($query); I'm thinking I should use an If statement, but what should the condition be? if ( $number_three == 3 ) { //adds content to theme } else { //php headers redirect to 404 page } Any help? Thanks Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted August 15, 2009 Share Posted August 15, 2009 $query = mysql_query("SELECT * from `page` WHERE id='$pg'") or die(mysql_error()); if(mysql_num_rows($query)) ==0) { header("Location: your404page.php"); exit; } $row=mysql_fetch_array($query); // The rest of your code here Quote Link to comment Share on other sites More sharing options...
peter_anderson Posted August 15, 2009 Author Share Posted August 15, 2009 $query = mysql_query("SELECT * from `page` WHERE id='$pg'") or die(mysql_error()); if(mysql_num_rows($query)) ==0) { header("Location: your404page.php"); exit; } $row=mysql_fetch_array($query); // The rest of your code here Thanks You had an extra bracket, but it works 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.