Jump to content

Need help with if then


jcran

Recommended Posts

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

<?

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/")

}

?>

<?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.
  }
}

?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.