jcran Posted July 30, 2008 Share Posted July 30, 2008 I need to modify a php script to forward to the main page if an ID # is not found. For example, some pages are showing up in the search engines, but the record has already been deleted from the database so the page just comes up white. This is the script. <? require_once("includes/config.php"); $db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error()); $db_select = mysql_select_db ($DBName) or die (mysql_error()); $db_table = $TBL_PR . "events"; $query = "SELECT * FROM $db_table WHERE event_id='$_GET[id]' LIMIT 1"; $query_result = mysql_query ($query); while ($info = mysql_fetch_array($query_result)){ $date = date ("l, jS F Y", mktime(0,0,0,$info['event_month'],$info['event_day'],$info['event_year'])); $time_array = split(":", $info['event_time']); $time = date ("g:ia", mktime($time_array['0'],$time_array['1'],0,$info['event_month'],$info['event_day'],$info['event_year'])); ?> Link to comment https://forums.phpfreaks.com/topic/117275-need-help-with-if-then/ Share on other sites More sharing options...
atlanta Posted July 30, 2008 Share Posted July 30, 2008 <? require_once("includes/config.php"); $db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error()); $db_select = mysql_select_db ($DBName) or die (mysql_error()); $db_table = $TBL_PR . "events"; $query = "SELECT * FROM $db_table WHERE event_id='$_GET[id]' LIMIT 1"; $query_result = mysql_query ($query); if(mysql_num_rows($query_result) > 0) { while ($info = mysql_fetch_array($query_result)){ $date = date ("l, jS F Y", mktime(0,0,0,$info['event_month'],$info['event_day'],$info['event_year'])); $time_array = split(":", $info['event_time']); $time = date ("g:ia", mktime($time_array['0'],$time_array['1'],0,$info['event_month'],$info['event_day'],$info['event_year'])); } } else { header("Location: http://domain.com/") } ?> Link to comment https://forums.phpfreaks.com/topic/117275-need-help-with-if-then/#findComment-603264 Share on other sites More sharing options...
jcran Posted July 30, 2008 Author Share Posted July 30, 2008 Thats not working, I get this: Parse error: syntax error, unexpected '}' in /home/pcg/polkcountygolf-www/calendar/event.php on line 20 Link to comment https://forums.phpfreaks.com/topic/117275-need-help-with-if-then/#findComment-603293 Share on other sites More sharing options...
trq Posted July 30, 2008 Share Posted July 30, 2008 <?php require_once("includes/config.php"); $db_connection = mysql_connect ($DBHost, $DBUser, $DBPass) OR die (mysql_error()); $db_select = mysql_select_db ($DBName) or die (mysql_error()); $db_table = $TBL_PR . "events"; $query = "SELECT * FROM $db_table WHERE event_id='$_GET[id]' LIMIT 1"; if ($query_result = mysql_query ($query)) { if (mysql_num_rows($query_result)) { $info = mysql_fetch_array($query_result); $date = date ("l, jS F Y", mktime(0,0,0,$info['event_month'],$info['event_day'],$info['event_year'])); $time_array = split(":", $info['event_time']); $time = date ("g:ia", mktime($time_array['0'],$time_array['1'],0,$info['event_month'],$info['event_day'],$info['event_year'])); } else { header("Location: mainpage.php"); // <-- here is the redirect. } } ?> Link to comment https://forums.phpfreaks.com/topic/117275-need-help-with-if-then/#findComment-603295 Share on other sites More sharing options...
jcran Posted July 30, 2008 Author Share Posted July 30, 2008 Still no luck, same error. Link to comment https://forums.phpfreaks.com/topic/117275-need-help-with-if-then/#findComment-603302 Share on other sites More sharing options...
chacha102 Posted July 30, 2008 Share Posted July 30, 2008 Is there any other code in the page itself? Not the include (PHP would tell you its a different page with an error), but just the page. Link to comment https://forums.phpfreaks.com/topic/117275-need-help-with-if-then/#findComment-603311 Share on other sites More sharing options...
jcran Posted July 30, 2008 Author Share Posted July 30, 2008 Only code to reference the query. The page works when an id is still in the database. For example, if someone finds a paticular record in the search engine with /event.php?id=4 and it has been deleted, the page just comes up blank. But, if someone finds the page with /event.php?id=12, which is still in the database it works fine. I want the page that is found with an id that has been deleted to forward to another page. Link to comment https://forums.phpfreaks.com/topic/117275-need-help-with-if-then/#findComment-603383 Share on other sites More sharing options...
trq Posted July 30, 2008 Share Posted July 30, 2008 Put this at the top of the script. <?php ini_set('display_errors','1'); error_reporting(E_ALL); ?> Link to comment https://forums.phpfreaks.com/topic/117275-need-help-with-if-then/#findComment-603409 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.