2011-08-09 65 views
0

爲什麼笨使用重定向後,我有這樣的錯誤:錯誤310(淨值:: ERR_TOO_MANY_REDIRECTS)

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

如果使用這樣的:redirect('admin/hotel/insert', 'refresh');,刷新頁面,馬不停蹄,爆裂。
我該怎麼辦?

我在控制器hotel碼(function):

function insert(){ 
    $this->load->view('admin/hotel_submit_insert'); 
     $today = jgmdate("j F Y"); 
     $data = array (
     'name' => $this->input->post('name', TRUE), 
     'star' => $this->input->post('star', TRUE), 
     'address' => $this->input->post('address', TRUE), 
     'number_phone' => $this->input->post('number_phone', TRUE), 
     'fax' => $this->input->post('fax', TRUE), 
     'site' => $this->input->post('site', TRUE), 
     'email' => $this->input->post('email', TRUE), 
     'useradmin' => $this->input->post('useradmin', TRUE), 
     'date' => $today , 
     ); 
     $this->db->insert('hotel_submits', $data); 
     redirect('admin/hotel/insert'); // after use of this 
    } 

對於

+0

您可能需要爲重定向停止條件。插入後不是將用戶重定向到同一頁嗎?由於這個原因,您還可以檢查數據庫現在是否已滿空記錄。 – s3v3n

+0

是的,插入後它會進入同一頁面。解釋更多。我需要更改代碼嗎? –

回答

-3

好了,所以你需要確保插入僅發生一次。

因此,您需要檢查發佈數據是否可用,然後再運行重定向。這裏發生的事情是代碼不斷插入數據並重定向頁面。

function insert(){ 

// If you are posting data do the insert 
if (isset($this->input->post('name')) && strlen($this->input->post('name')) //just double checking. 
{ 
    $today = jgmdate("j F Y"); 
    $data = array (
     'name' => $this->input->post('name', TRUE), 
     'star' => $this->input->post('star', TRUE), 
     'address' => $this->input->post('address', TRUE), 
     'number_phone' => $this->input->post('number_phone', TRUE), 
     'fax' => $this->input->post('fax', TRUE), 
     'site' => $this->input->post('site', TRUE), 
     'email' => $this->input->post('email', TRUE), 
     'useradmin' => $this->input->post('useradmin', TRUE), 
     'date' => $today , 
    ); 
    if($this->db->insert('hotel_submits', $data)) 
     redirect('admin/hotel/insert'); 
} 

//And load the view 
$this->load->view('admin/hotel_submit_insert'); 

}

+1

這是歇斯底里,複製/粘貼作業25分鐘後得到答案..很好。 – jondavidjohn

+0

實際上,在'isset()'的php文檔中有一個很大的紅色框,指出isset()只能用於變量,'$ this-> input-> post()'是一個函數。即使它是DID的工作,它總是會是真的。 – jondavidjohn

0

嘗試做這樣的...

function insert(){ 

    // If you are posting data, do the insert 
    if ($_POST) 
    { 
     $today = jgmdate("j F Y"); 
     $data = array (
      'name' => $this->input->post('name', TRUE), 
      'star' => $this->input->post('star', TRUE), 
      'address' => $this->input->post('address', TRUE), 
      'number_phone' => $this->input->post('number_phone', TRUE), 
      'fax' => $this->input->post('fax', TRUE), 
      'site' => $this->input->post('site', TRUE), 
      'email' => $this->input->post('email', TRUE), 
      'useradmin' => $this->input->post('useradmin', TRUE), 
      'date' => $today , 
     ); 
     $this->db->insert('hotel_submits', $data); 
    } 

    // then load the view no matter what 
    $this->load->view('admin/hotel_submit_insert'); 
} 
相關問題