This topic is locked

User Still allow update actual checkin > 24 Hours on before update

11/30/2016 1:30:48 PM
PHPRunner General questions
J
jackwood author

I want to validate, before update.

If User update checkintime > 24 Hours from checkin confirmation, it must Forbid update record. But If Less 24 Hour user allow to update record.
I dont know, why this code still allow update record more than 24 hour

===============================================================================================================
$day1 = date('Y-m-d H:i:s');

$day1 = strtotime($day1);
$day2 = $values["Checkin"];

$day2 = strtotime($day2);
$diffHours = round(($day2 - $day1) / 3600);
if($diffHours > 24)

{

$message="<div class=message style='color:red' align=center><<< Checkin is not allowed > 24 hours from confirmation . >>></div>";

return false;

}

else

{

$values["Checkintime"]= date('Y-m-d H:i:s');

return true;

}
=============================

Please Help.

Sergey Kornilov admin 11/30/2016

You need to add some debug info like below to see what exactly is happening.

$day1 = date('Y-m-d H:i:s');

echo $day1."
";

$day1 = strtotime($day1);
$day2 = $values["Checkin"];

echo $day2."
";

$day2 = strtotime($day2);
$diffHours = round(($day2 - $day1) / 3600);

echo $diffHours."
";


This should point you in the right direction.

J
jackwood author 12/1/2016



You need to add some debug info like below to see what exactly is happening.

$day1 = date('Y-m-d H:i:s');

echo $day1."
";

$day1 = strtotime($day1);
$day2 = $values["Checkin"];

echo $day2."
";

$day2 = strtotime($day2);
$diffHours = round(($day2 - $day1) / 3600);

echo $diffHours."
";


This should point you in the right direction.


Hi Sergey,

Thanks for the reply.
I Change my Code with your suggestion like this.

--------------------------------------------------------

$day1 = date('Y-m-d H:i:s');

echo $day1."
";

$day1 = strtotime($day1);

echo $day1."
";
$day2 = date("Y-m-d H:i:s",strtotime($values["Checkin"]));

echo $day2."
";

$day2 = strtotime($day2);

echo $day2."
";
$diffHours = round(($day2 - $day1) / 3600);

echo $diffHours."
";
-------------------------------------------------------------------------------------------------

And I've got direction with this:


It should work if I Change my Code to here before record update, But it doesn't work (record Still update), hufh..
-------------------------------------------------------------------------------------------------

if($values["checkin_flag"]== 1 )

{
$day1 = date("Y-m-d H:i:s");

$day1 = strtotime($day1);
$day2 = date("Y-m-d H:i:s",strtotime($values["Checkin"]));
$diffHours = round(($day2 - $day1) / 3600);
if($diffHours >24)

{

$message="<div class=message style='color:red' align=center><<< Tanggal Checkin tidak Valid. >>></div>";

return false;

}

else

{

$values["Checkintime"]= now() ;

}
}

return true;

Sergey Kornilov admin 12/1/2016

There is no screenshot

J
jackwood author 12/1/2016



There is no screenshot


maybe this is the correct link:

Captures

Sergey Kornilov admin 12/2/2016

Makes sense to me. Ten days, 247 hours.