Trying to fix an error that Ive encountered with some code.
I tried editing the model but nothing has worked. Also edited the controller, updated DB as well was made sure certain folders were in parent directory. Trying to figure out how to fix this error. If anyone can help it would be greatly appreciated!!!
View:
<?php
if(file_exists('/assets/images/'.$user_data[0]->profile_pic) && isset($user_data[0]->profile_pic)){
$profile_pic = $user_data[0]->profile_pic;
}else{
$profile_pic = 'user.png';}?>
<center> <img class="thumb-image setpropileam" src="<?php echo base_url();?>/assets/images/<?php echo isset($profile_pic)?$profile_pic:'user.png';?>" alt="User profile picture"></center>
Model:
<?php
class User_model extends CI_Model {
function __construct(){
parent::__construct();
$this->user_id =isset($this->session->get_userdata()['user_details'][0]->id)?$this->session->get_userdata()['user_details'][0]->users_id:'1';
}
/**
* This function is used authenticate user at login
*/
function auth_user() {
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->db->where("is_deleted='0' AND (name='$email' OR email='$email')");
$result = $this->db->get('users')->result();
if(!empty($result)){
if (password_verify($password, $result[0]->password)) {
if($result[0]->status != 'active') {
return 'not_varified';
}
return $result;
}
else {
return false;
}
} else {
return false;
}
}
/**
* This function is used to delete user
* @param: $id - id of user table
*/
function delete($id='') {
$this->db->where('users_id', $id);
$this->db->delete('users');
}
/**
* This function is used to load view of reset password and varify user too
*/
function mail_varify() {
$ucode = $this->input->get('code');
$this->db->select('email as e_mail');
$this->db->from('users');
$this->db->where('var_key',$ucode);
$query = $this->db->get('cultured_codeignite');
$result = $query->row();
if(!empty($result->e_mail)){
return $result->e_mail;
}else{
return false;
}
}
/**
* This function is used Reset password
*/
function ResetPpassword(){
$email = $this->input->post('email');
if($this->input->post('password_confirmation') == $this->input->post('password')){
$npass = password_hash($this->input->post('password'), PASSWORD_DEFAULT);
$data['password'] = $npass;
$data['var_key'] = '';
return $this->db->update('users',$data, "email = '$email'");
}
}
/**
* This function is used to select data form table
*/
function get_data_by($tableName='users', $value='', $colum='',$condition='') {
if((!empty($value)) && (!empty($colum))) {
$this->db->where($colum, $value);
}
$this->db->select('*');
$this->db->from($tableName);
$query = $this->db->get('cultured_codeignite');
return $query->result();
}
/**
* This function is used to check user is alredy exist or not
*/
function check_exists($table='', $colom='',$colomValue=''){
$this->db->where($colom, $colomValue);
$res = $this->db->get($table)->row();
if(!empty($res)){ return false;} else{ return true;}
}
/**
* This function is used to get users detail
*/
function get_users($userID = '') {
$this->db->where('is_deleted', '0');
if(isset($userID) && $userID !='') {
$this->db->where('users_id', $userID);
} else if($this->session->userdata('user_details')[0]->user_type == 'admin') {
$this->db->where('user_type', 'admin');
} else {
$this->db->where('users.users_id !=', '1');
}
$result = $this->db->get('users')->result();
return $result;
}
/**
* This function is used to get email template
*/
function get_template($code){
$this->db->where('code', $code);
return $this->db->get('templates')->row();
}
/**
* This function is used to Insert record in table
*/
public function insertRow($table, $data){
$this->db->insert($table, $data);
return $this->db->insert_id();
}
/**
* This function is used to Update record in table
*/
public function updateRow($table, $col, $colVal, $data) {
$this->db->where($col,$colVal);
$this->db->update($table,$data);
return true;
}
}
Here is the error:
Severity: Notice
Message: Undefined variable: user_data
Filename: views/profile.php
Line Number: 475
Backtrace:
File: /home4/cultured/public_html/application/views/profile.php Line: 475 Function: _error_handler
File: /home4/cultured/public_html/application/controllers/Login.php Line: 47 Function: view
File: /home4/cultured/public_html/index.php Line: 315 Function: require_once A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/profile.php
Line Number: 475
put the code in you controller function in line number /home4/cultured/public_html/application/controllers/Login.php Line: 47
The user data array should be there while returning the data to the view If it is not there you will get the error
$data["user_data"] = ""; // Your user_data query result should be here
$this->load->view("profile", $data);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.