2017-07-18 66 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

其实它不是形式。这只是一个页面 –