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 Link to comment https://forums.phpfreaks.com/topic/170413-solved-if-column-exists-if-not/ 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 Link to comment https://forums.phpfreaks.com/topic/170413-solved-if-column-exists-if-not/#findComment-898951 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 Link to comment https://forums.phpfreaks.com/topic/170413-solved-if-column-exists-if-not/#findComment-898955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.