Reputation: 121
I have a problem here where when I reserved book from this date (for example 09/07/2013 as the date reserved and 09/11/2013 as the expiration date). To check if it is forfeited I logout then change my calendar date to 09/11/2013, then when I refresh the login.form it says webpage has a redirect loop.
<?php
class Login extends CI_Controller{
function index()
{
$this->load->model('admin/confirmation_model');
$data['confirmation'] = $this->confirmation_model->getConfirm();
$data['main_content'] = 'login_form';
$this->load->view('includes/template', $data);
}
//added function update
function update($isbn){
$statuses = 'Forfeited';
$data = array(
'status' => $statuses
);
$this->db->where('isbn',$isbn);
$this->db->update('reserved_dummy',$data);
$sql = 'update books set stock=stock+1 where isbn=?';
$this->db->query($sql, $isbn);
redirect('login');
}
this is my view:
<?php $date = date('m/d/Y');
$tomorrow = date('m/d/Y',strtotime($date));
if ($confirmation) {
foreach($confirmation as $r) {
if (date('m/d/Y',strtotime($r->date_expire . "+1 days")) == $tomorrow && $r->status != 'forfeited') {
redirect('login/update/'.$r->isbn,'location');
}
}
}
?>
Upvotes: 0
Views: 255
Reputation: 9130
I believe the issue may be related to your use of "American" style dates (m/d/Y). This is a very ambiguous format for computers. Try the following and see what happens.
Change all date('m/d/Y')
to date('Y-m-d')
.
The reason why; because when you pass '09/08/2013'
to strtotime()
, a 'guess' is made by PHP. The reason for the guess? Almost only Americans read their dates in m/d/Y
format. For example, I read this date as 9th of Aug, 2013, but Americans would say it was the 8th of Sept, 2013.
If you pass '2013-09-08'
to strtotime()
there is no confusion as this is always interpreted as 'Y-m-d' format.
Upvotes: 1