2016-11-08 12 views
1

ユーザーがWebサイトにログインすると、プロファイルIDに基づいてログインユーザーの詳細が取得されます。更新できないユーザーの詳細も更新しようとするとどんな問題も起こらないとして。codeigniterを使用してユーザーログインした後にプロファイルデータをデータベースに更新できません

コントローラー:

function index() 
{ 
    if($this->session->userdata('admin_logged_in')) 
    { 
     $data['admin_details'] = $this->session->userdata('admin_logged_in'); 
     $data['country'] = $this->signup_model->getcountry();  
     $data['states'] = $this->profile_model->getstates(); 
     $data['records']= $this->profile_model->getprofiledata($this->session->userdata('admin_logged_in')['profile_id']); 
     $data['mainpage']='profile'; 
     //echo '<pre>'.print_r($data, true).'</pre>'; 
     $this->load->view('templates/template',$data); 
     $this->load->view('templates/sidebar',$data); 
    } 
    else 
    {   
     $this->load->view('welcome'); 
    } 
} 

function updateprofile() 
{ 
    $this->load->library('form_validation'); 
    $this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>'); 
    $this->form_validation->set_rules('first_name','First Name','required'); 
    $this->form_validation->set_rules('profile_name','Profile Name','required'); 
    $this->form_validation->set_rules('designation','Designation','required'); 
    $this->form_validation->set_rules('address_1','Address','required'); 
    $this->form_validation->set_rules('address_2','Address','required'); 

    if($this->form_validation->run()== FALSE) 
    { 
    $data['records']= $this->profile_model->getprofiledata($this->session->userdata('admin_logged_in')['profile_id']);  
    $data['mainpage']='profile'; 
    $this->load->view('templates/template',$data); 
    $this->load->view('templates/sidebar',$data); 
    } 
    else  
     {  
      $result = $this->profile_model->update($this->input->post('profile_id'));  
      if(is_array($result)) 
      {  
       $data['errors']=$result; 
       $data['records']= $this->profile_model->getprofiledata($this->session->userdata('admin_logged_in')['profile_id']);     
       $data['mainpage']='profile'; 
       $this->load->view('templates/template',$data); 
       $this->load->view('templates/sidebar',$data); 
      }        
       else      
       $this->flash->success('<h2>Successfully Updated the record.<h2>');      
       redirect('profile');      
     }    

} 

モデル:

function getprofiledata($id) 
{ 
    $this->db->select('profile_details.*,C.country_name,S.state_name,D.city_name');  
    $this->db->from('profile_details'); 
    $this->db->join('countries AS C','C.country_id=profile_details.country_id','INNER'); 
    $this->db->join('states AS S','S.state_id=profile_details.state_id','INNER'); 
    $this->db->join('cities AS D','D.city_id=profile_details.city_id','INNER'); 
    $this->db->where(array('profile_details.profile_id'=>$id));  
    $q=$this->db->get();   
    if($q->num_rows()>0) 
     { 
    return $q->result(); 
     } 
    else 
    { 
    return false; 
    } 
} 

function update($id) 
{ 
    $data=array(
    'first_name' =>$this->input->post('first_name'), 
    'profile_name' =>$this->input->post('profile_name'), 
    'designation' =>$this->input->post('designation'), 
    'address_1' =>$this->input->post('address_1'), 
    'address_2' =>$this->input->post('address_2')  
    ); 
    $this->db->where(array('profile_id'=>$id)); 
    $this->db->update('profile_details', $data); 
    return true;   
} 

ビュー:

<div class="col-md-3"> 
</div> 
<div class="col-md-9 col-md-offset-2"> 
<div id="legend"> 
    <legend class="">Profile Information</legend> 
</div> 
<?php if(isset($records) && is_array($records) && count($records)>0): ?> 
      <?php foreach($records as $r):?> 
    <form action="<?php echo base_url();?>profile/updateprofile" role="form" class="form-horizontal" id="location" method="post" accept-charset="utf-8"> 
    <?php 
     echo form_hidden('profile_id',$r->profile_id); 
    ?> 
    <div class="form-group"> 
     <label class="control-label col-sm-2 " for="name">Name:</label> 
     <div class="col-sm-4 col-sm-offset-1"> 
     <input type="text" class="form-control" nae="first_name" id="first_name" placeholder="Enter name" value="<?php echo $r->first_name;?>" /> 
     </div> 
    </div> 
    <div class="form-group"> 
     <label class="control-label col-sm-2 " for="profilename">Profile Name:</label> 
     <div class="col-sm-4 col-sm-offset-1"> 
     <input type="text" class="form-control" name="profile_name" id="profile_name" placeholder="Enter Profile name" value="<?php echo $r->profile_name;?>" /> 
     </div> 
    </div> 
    <div class="form-group"> 
     <label class="control-label col-sm-2 " for="designation">Designation:</label> 
     <div class="col-sm-4 col-sm-offset-1"> 
     <input type="text" class="form-control" name="designation" id="designation" placeholder="Enter Designation" value="<?php echo $r->designation;?>" /> 
     </div> 
    </div> 
    <div class="form-group"> 
     <label class="control-label col-sm-2 " for="address_1">Address 1:</label> 
     <div class="col-sm-4 col-sm-offset-1"> 
     <input type="text" class="form-control" id="address_1" name="address_1" placeholder="Enter Address Details" value="<?php echo $r->address_1;?>" /> 
     </div> 
    </div> 
    <div class="form-group"> 
     <label class="control-label col-sm-2 " for="address_2">Address 2:</label> 
     <div class="col-sm-4 col-sm-offset-1"> 
     <input type="text" class="form-control" id="address_2" name="address_2" placeholder="Enter Address Details" value="<?php echo $r->address_2;?>" /> 
     </div> 
    </div> 
    <button type="submit" class="btn">Submit</button> 
    </form> 
    <?php endforeach;endif;?> 
    </div> 

一度フォームのリダイレクトを提出database.Onceにデータを更新することができないウェブサイトへのユーザーのログイン同じページには何の問題もない。

+0

それは事前 – user7047368

+0

で私の感謝のために本当に便利になります任意のヘルプ「名前」に「NAE」いずれ私にこの – user7047368

+0

いずれかを助けることができる。このようもなくしようとしました。この問題 – user7047368

答えて

0

親愛なるuser7047368、お使いの機種コードで

たぶん問題。

function update($id) 
{ 
    $data=array(
    'first_name' =>$this->input->post('first_name'), 
    'profile_name' =>$this->input->post('profile_name'), 
    'designation' =>$this->input->post('designation'), 
    'address_1' =>$this->input->post('address_1'), 
    'address_2' =>$this->input->post('address_2'), 

    ); 
    $this->db->where(array('profile_id'=>$id)); 
    $this->db->update('profile_details', $data); 
    return true;   
} 

はあなたが$this->db->update('profile_details', $data);後、この機能には、このラインvar_dump($this->db->last_query());を置くことができ、クエリが真か偽かわからない場合は

function update($id) 
{ 
    $data=array(
    'first_name' =>$this->input->post('first_name'), 
    'profile_name' =>$this->input->post('profile_name'), 
    'designation' =>$this->input->post('designation'), 
    'address_1' =>$this->input->post('address_1'), 
    'address_2' =>$this->input->post('address_2') 
    ); 
    $this->db->where(array('profile_id'=>$id)); 
    $this->db->update('profile_details', $data); 
    return true;   
} 

を(あなたが$data(array)内の余分なコンマを入力)する必要があります。それをコピーしてphpmyadminの質問フォームに貼り付けてください。

このヘルプが必要です。

+0

で私を助けてくださいしてくださいphpmyadminで印刷するクエリを取得する – user7047368

+0

クエリを印刷していません – user7047368

0

問題は、あなたのビュー

使用中の代わりにあなたの最初の名前の入力フィールドで

<div class="form-group"> 
    <label class="control-label col-sm-2 " for="name">Name:</label> 
    <div class="col-sm-4 col-sm-offset-1"> 
    <input type="text" class="form-control" nae="first_name" id="first_name" placeholder="Enter name" value="<?php echo $r->first_name;?>" /> 
    </div> 
</div> 

のこの

<div class="form-group"> 
    <label class="control-label col-sm-2 " for="name">Name:</label> 
    <div class="col-sm-4 col-sm-offset-1"> 
    <input type="text" class="form-control" name="first_name" id="first_name" placeholder="Enter name" value="<?php echo $r->first_name;?>" /> 
    </div> 
</div> 

は '名前' 属性は、スペルの間違いがあります。 正しいこと

+0

いいえ修正されたスペルミスも修正されていません – user7047368

+0

まだ変更されていません – user7047368

関連する問題