[eluser]xentova[/eluser]
this is my controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Edit_profile extends MY_Controller{
function __construct(){
parent::MY_Controller();
}
public function index(){
$this->output->enable_profiler(TRUE);
$this->load->library('form_validation');
$this->load->model('user_model');
$session_data = $this->session->userdata('logged_in');
$data= array(
'username' =>$session_data['username']
);
$username = $data['username'];
$data = $this->user_model->edit_profile($username);
$this->form_validation->set_rules('email_add', 'Email Address', 'trim|required|valid_email|callback_email_check');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('confirm_password', 'Password Confirmation', 'trim|required|matches[password]');
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
if(! $this->session->userdata('logged_in')){
$this->load->view('pages/index');
redirect('', 'refresh');
}
if($this->form_validation->run() == FALSE){
$this->load->view('edit_profile/index', $data);
$this->load->view('templates/footer');
}
else{
$this->user_model->login('username', 'password');
redirect('', 'refresh');
}
}
public function username_check($str){
$this->load->model('user_model');
if ($this->user_model->checkUsername($str)){
return true;
}
else{
$this->form_validation->set_message('username_check', 'The Username already exist');
return false;
}
}
public function email_check($str){
$this->load->model('user_model');
if ($this->user_model->checkEmail($str)){
return true;
}
else{
$this->form_validation->set_message('email_check', 'The Email address already exist');
return false;
}
}
}
?>
this is my model
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_model extends CI_Model{
public function __construct(){
parent::__construct();
}
public function login($username,$password){
$this -> db -> select('id, username, password, first_name, last_name');
$this -> db -> from('users');
$this -> db -> where('username', $username);
$this -> db -> where('password', MD5($password));
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1){
return $query->result();
}
else{
return false;
}
}
public function add_user(){
$data=array(
'username'=>$this->input->post('username'),
'email_add'=>$this->input->post('email_add'),
'password'=>md5($this->input->post('password')),
'first_name'=>$this->input->post('first_name'),
'last_name'=>$this->input->post('last_name')
);
$this->db->insert('users',$data);
}
function checkUsername($username){
$this->db->where('username', $username);
$query = $this->db->get('users');
if ($query->num_rows() > 0){
return false;
}
else{
return true;
}
}
function checkEmail($email_add){
$this->db->where('email_add', $email_add);
$query = $this->db->get('users');
if($session_data['email_add'] = $email_add){
return true;
}
if ($query->num_rows() > 0){
return false;
}
else{
return true;
}
}
public function edit_profile($username){
$this -> db -> select('password, first_name, last_name, email_add');
$this -> db -> from('users');
$this -> db -> where('username', $username);
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1){
return $query->result();
}
else{
return false;
}
}
}
?>
this is my view
Code:
<?php echo validation_errors();
echo form_open("edit_profile");
?>
<h5>Email Address</h5>
<input type="email" name="email_add" value="<?php echo set_value('email_add', $email_add); ?>" size="20" />
<h5>Password</h5>
<input type="password" name="password" value="" size="20" />
<h5>Confirm password</h5>
<input type="password" name="confirm_password" value="" size="20" />
<h5>First Name</h5>
<input type="text" name="first_name" value="<?php echo set_value('first_name', $first_name); ?>" size="20" />
<h5>Last Name</h5>
<input type="text" name="last_name" value="<?php echo set_value('last_name', $last_name); ?>" size="20" />
<div><input type="submit" value="Submit" /></div>
<?php echo form_close(); ?>
PROBLEM: $email_add is undefined
im making a page for users to edit their profile. so when they go to the page, the values of each field should hv been set in by default. thing is, all the values i set_value are ok except for the $email_add variable. i've used var_dump() and profiler at controller and the variable seems to pass but it always shows up as undefined. i wil lsee this in my password field: <div after that it will show
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: email_add
Filename: edit_profile/index.php
Line Number: 6
" size="20" />