2017-07-18 97 views
0

我編寫了代碼,用於檢查用戶是否具有DB中的所有必需信息。如果用戶有,什麼都不做,但是如果他們是空的,重定向到continueregistration頁面。但是,當它重定向它寫道,重定向到代碼錯誤的url

本頁面無法正常工作

本地主機重定向你太多次。嘗試清除您的Cookie。 ERR_TOO_MANY_REDIRECTS

我清除了我的緩存它沒有工作。這是我的觀點:

<?php 

    if($this->session->userdata('logged_in')) { 
    $query = $this->db->get_where('instructors', array('id' => $this->session->userdata('id'))); 

    $insdatacheck = $query->row_array(); 

    if($insdatacheck['name'] == '') { 
     redirect('/user/continueregistration/'); 
    } else { ?> 
     <script type="text/javascript">alert('hello');</script> 
     <?php 
    } 

    } 

?> 

和控制器:

function continueregistration() { 

     //set validation rules 
     $this->form_validation->set_rules('name', 'name', 'trim|required|alpha|min_length[2]|max_length[30]'); 
     $this->form_validation->set_rules('web', 'web adress', 'trim|required|valid_url|prep_url|min_length[3]'); 
     $this->form_validation->set_rules('facebook', 'facebook adress', 'trim|valid_url|prep_url|min_length[3]'); 
     $this->form_validation->set_rules('twitter', 'twitter adress', 'trim|valid_url|prep_url|min_length[3]'); 
     $this->form_validation->set_rules('youtube', 'youtube adress', 'trim|valid_url|prep_url|min_length[3]'); 
     $this->form_validation->set_rules('instagram', 'instagram adress', 'trim|valid_url|prep_url|min_length[3]'); 
     $this->form_validation->set_rules('tel', 'telephone number', 'trim|required|alpha_numeric_spaces|min_length[3]|max_length[30]'); 
     $this->form_validation->set_rules('address', 'address', 'trim|required|alpha_numeric_spaces|min_length[3]|max_length[30]'); 
     $this->form_validation->set_rules('insdescription', 'description', 'trim|required|alpha_numeric_spaces|min_length[3]'); 

     $data['title'] = 'Continue Registration'; 
     $data['instructors'] = $this->single_instructor_model->get_instructor_info(); 

      $this->load->view('templates/header'); 
      $this->load->view('registration/registration', $data); 
      $this->load->view('templates/footer'); 

     //validate form input 
     if ($this->form_validation->run() == FALSE) 
     { 
      // fails 
      $this->load->view('templates/header'); 
      $this->load->view('registration/registration', $data); 
      $this->load->view('templates/footer'); 
     } 
     else 
     { 
      //insert the user registration details into database 
      $dataforreg = array(
       'name' => $this->input->post('name'), 
       'web' => $this->input->post('web'), 
       'fb' => $this->input->post('facebook'), 
       'twitter' => $this->input->post('twitter'), 
       'youtube' => $this->input->post('youtube'), 
       'instagram' => $this->input->post('instagram'), 
       'phone' => $this->input->post('tel'), 
       'address' => $this->input->post('address'), 
       'description' => $this->input->post('insdescription') 
      ); 

      // insert form data into database 
      if ($this->user_model->updateUser($dataforreg, $to_email)) { 
        redirect('homepage/index'); 

      } 
      else 
      { 
       // error 
       $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Error</div>'); 
        redirect('user/continueregistration'); 
      } 
     } 


    } 
+1

這意味着你有一個重定向循環 –

+1

你認爲你有什麼代碼?它應該真的在控制器中。雖然。一個視圖純粹是爲了演示。視圖中不應該有任何業務邏輯或流量控制。 –

+1

你打電話繼續註冊continueregistration – inarilo

回答

0

我想你遇到了 「確認重新提交表單」 的消息。它發生在你的用戶不可用時。它指向用戶/繼續註冊,並且您只是重新定向而不刷新,然後它將數據發送到數據庫並繼續重定向。由於它,你應該設置:重定向('鏈接','刷新');並確認一個提交按鈕,如果它被點擊,然後執行裏面的操作。

if(isset($_POST['submit'])   //button with the name "submit" 
{ 
    //action 
} 
+0

其實它不是形式。這只是一個頁面 –