2011-08-09 16 views
0

のCodeIgniterでのリダイレクトを使用した後、私はこのエラーを持っている理由:エラー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()は変数にのみ使用されるべきであることを指摘する 'isset()'のphp docsに大きな赤いボックスがあります。 '$ this-> input-> post()'は関数です。たとえそれが機能していても、常に真実になります。 – 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'); 
} 
関連する問題