This topic is locked

Redirect to view page if record older than 1 day

6/18/2008 3:15:31 PM
PHPRunner General questions
M
mrpeeble author

I want to redirect to view page when user clicks Edit for all records that have a MONAssignDate older than 1 day.
I tried this in BeforeProcessEdit:
$arr = db2time($data["MONAssignDate"]);

$t = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);

// compare time with current time subtracted by 1 days

if($t < time()-16060*24)

{

header("Location: SA_Monthly_Payment_Review_view.php?editid1=".$_REQUEST["editid1"]);

exit();

}
I get an error when I click on the edit link of the list page:
Error type 8

Error description Undefined offset: 3

URL 137.15.236.240/Officec/5percent_may2008/SA_Monthly_Payment_Review_edit.php?editid1=159

Error file D:\WebDev\OfficeC\5percent_may2008\include\SA_Monthly_Payment_Review_events.php

Error line 174

SQL query
if anyone can provide some insight i would be most appreciative.

J
Jane 6/19/2008

Hi,
try to use this code:

if ($data["MONAssignDate"])

{

$arr = db2time($data["MONAssignDate"]);

$t = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);

// compare time with current time subtracted by 1 days

if($t < time()-16060*24)

{

header("Location: SA_Monthly_Payment_Review_view.php?editid1=".$_REQUEST["editid1"]);

exit();

}

}

M
mrpeeble author 6/19/2008

Hi,

try to use this code:


Jane,
thank you for your reply. I inserted the code in BeforeProcessEdit function.
It still does not work, I always get the edit page and no redirect to the view page no matter what the date is in MONAssignDate. Perhaps the code goes in another event function?

J
Jane 6/20/2008

Hi,
please make sure $data array is declare and fill in your event.

M
mrpeeble author 6/20/2008

Hi,

please make sure $data array is declare and fill in your event.


Jane,
The entire BeforeProcessEdit looks like this:

{

global $conn;

$str = "select MONAssignDate from pr_mon_main where ID=".$_REQUEST["editid1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
if ($data["MONAssignDate"])

{

$arr = db2time($data["MONAssignDate"]);

$t = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);

// compare time with current time subtracted by 1 days

if($t < time()-16060*24)

{

header("Location: SA_Monthly_Payment_Review_view.php?editid1=".$_REQUEST["editid1"]);

exit();

}

}
}

Oddly enough, the only occassion where the redirect is going to the view page is for a record where the MONAssignDate is equal to june 18, 2008. Records for may march and april 2008 still are not redirecting to the view page.

M
mrpeeble author 6/20/2008



Jane,
The entire BeforeProcessEdit looks like this:

{

global $conn;

$str = "select MONAssignDate from pr_mon_main where ID=".$_REQUEST["editid1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
if ($data["MONAssignDate"])

{

$arr = db2time($data["MONAssignDate"]);

$t = mktime($arr[3],$arr[4],$arr[5],$arr[1],$arr[2],$arr[0]);

// compare time with current time subtracted by 1 days

if($t < time()-16060*24)

{

header("Location: SA_Monthly_Payment_Review_view.php?editid1=".$_REQUEST["editid1"]);

exit();

}

}
}

Oddly enough, the only occassion where the redirect is going to the view page is for a record where the MONAssignDate is equal to june 18, 2008. Records for may march and april 2008 still are not redirecting to the view page.


oops nevermind, I was doing something stupid again ! It works fine now. Thank you so much for your help Jane, you are the best.