<?php
class Profile extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('profile_model');
}
function index(){
$this->load->model('profile_model');
if($profile=$this->profile_model->show()){
$data=array(
'firstname'=>$profile[0]->firstName,
'lastname'=>$profile[0]->lastName,
'dob'=>$profile[0]->dob,
'profileImage'=>$profile[0]->profileImage
);
$this->load->view('profile_view',$data);
}else{
$data['profile_err']="No data to display";
$this->load->view('profile_view',$data);
}
}
function update_data() {
$config['upload_path']="assets/img/";
$config['allowed_types']='jpg|jpeg|gif|png';
$config['overwrite']=TRUE;
$this->load->library('upload',$config);
$field_name="profilePic"; //pic controller name
if(!$this->upload->do_upload($field_name)){
$data=array('err'=>$this->upload->display_errors());
}else{
$upload_data = $this->upload->data();
//Returns array of containing all of the data related to the file you uploaded.
$file_name = $upload_data['file_name'];
$profileData = array(
'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'dob' => $this->input->post('dob'),
'profileImage' => "assets/img/".$file_name
);
}
$this->load->model('profile_model');
if($q=$this->profile_model->update_data($profileData)){
redirect('Profile');
//$this->load->view('Profile');
}
/*$this->load->model('profile_model');
if($this->profile_model->update_data($data))
$this->data_display();*/
}
}
<!--Name:Asha-->
<?php
class Profile_model extends CI_Model{
function show(){
$userAlias="asha";
$query=$this->db->query("SELECT * FROM profile WHERE userAlias='$userAlias'");
if($query->num_rows()>0){
return $query->result();
}else{
return FALSE;
}
}
function update_data($data){
$userAlias="asha";
$this->db->where('userAlias', $userAlias);
if($this->db->update('profile', $data)){
return TRUE;
}
}
}
?>
view
<!--Name:Asha-->
<?php echo form_open_multipart('profile/update_data');?>
<!--<form action="<?php //echo base_url(//'profile/update_data')?>" method="post">-->
<p><label>Firstname:</label><input type="text" name="firstname" value="<?php echo $firstname;?>"></p>
<p><label>Lastname:</label><input type="text" name="lastname" value="<?php echo $lastname;?>"></p>
<p><label>Dob:</label><input type="date" name="dob" value="<?php echo $dob;?>"></p>
<p><label>Profileimage:</label>
<img src="<?php echo base_url($profileImage) ;?>" width="100" height="100">
<?php echo form_upload('profilePic'); ?></p>
<input type="submit" name="submit" value="Update">
</form>
class Profile extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('profile_model');
}
function index(){
$this->load->model('profile_model');
if($profile=$this->profile_model->show()){
$data=array(
'firstname'=>$profile[0]->firstName,
'lastname'=>$profile[0]->lastName,
'dob'=>$profile[0]->dob,
'profileImage'=>$profile[0]->profileImage
);
$this->load->view('profile_view',$data);
}else{
$data['profile_err']="No data to display";
$this->load->view('profile_view',$data);
}
}
function update_data() {
$config['upload_path']="assets/img/";
$config['allowed_types']='jpg|jpeg|gif|png';
$config['overwrite']=TRUE;
$this->load->library('upload',$config);
$field_name="profilePic"; //pic controller name
if(!$this->upload->do_upload($field_name)){
$data=array('err'=>$this->upload->display_errors());
}else{
$upload_data = $this->upload->data();
//Returns array of containing all of the data related to the file you uploaded.
$file_name = $upload_data['file_name'];
$profileData = array(
'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'dob' => $this->input->post('dob'),
'profileImage' => "assets/img/".$file_name
);
}
$this->load->model('profile_model');
if($q=$this->profile_model->update_data($profileData)){
redirect('Profile');
//$this->load->view('Profile');
}
/*$this->load->model('profile_model');
if($this->profile_model->update_data($data))
$this->data_display();*/
}
}
<!--Name:Asha-->
<?php
class Profile_model extends CI_Model{
function show(){
$userAlias="asha";
$query=$this->db->query("SELECT * FROM profile WHERE userAlias='$userAlias'");
if($query->num_rows()>0){
return $query->result();
}else{
return FALSE;
}
}
function update_data($data){
$userAlias="asha";
$this->db->where('userAlias', $userAlias);
if($this->db->update('profile', $data)){
return TRUE;
}
}
}
?>
view
<!--Name:Asha-->
<?php echo form_open_multipart('profile/update_data');?>
<!--<form action="<?php //echo base_url(//'profile/update_data')?>" method="post">-->
<p><label>Firstname:</label><input type="text" name="firstname" value="<?php echo $firstname;?>"></p>
<p><label>Lastname:</label><input type="text" name="lastname" value="<?php echo $lastname;?>"></p>
<p><label>Dob:</label><input type="date" name="dob" value="<?php echo $dob;?>"></p>
<p><label>Profileimage:</label>
<img src="<?php echo base_url($profileImage) ;?>" width="100" height="100">
<?php echo form_upload('profilePic'); ?></p>
<input type="submit" name="submit" value="Update">
</form>
0 comments:
Post a Comment