[eluser]convan23[/eluser]
I'm currently creating the part of my app that involves the user handling...login/logout, registration, account control, etc.
I'm working on the register account function, specifically the form validation, and I'm running into a problem where it checks to see if the email entered into the form already exists in the database.
Here's the code that relates to the problem:
Quote:Fatal error: Call to a member function on a non-object in /mnt/gs01/herd02/6813/domains/ci.epiphanyeyc.com/html/system/application/controllers/users.php on line 37
Which refers to:
Code:
function _chekemail($str){
if($this->user_model->get_user('email',$str)){ return false; } else { return true; }
}
Which is in:
Controller:
Code:
function Users()
{
parent::Controller();
$this->load->library('encrypt');
$this->load->model('user_model','',TRUE);
}
function register()
{
$data['head_title'] = "Create an Account";
// Validation:
$this->load->library('validation');
$rules['firstname'] = "trim|required|xss_clean";
$rules['lastname'] = "trim|required|xss_clean";
$rules['email'] = "required|valid_email|_chekemail";
$rules['password'] = "required|matches[confirm]|min_length[6]";
$rules['confirm'] = "required";
$this->validation->set_message('required', '<p class="error"><strong>Required Field:</strong> Please enter your %s</p>');
$this->validation->set_message('valid_email', '<p class="error"><strong>Invalid Email:</strong> Either your %s is invalid or it is already in use.</p>');
$this->validation->set_message('min_length', '<p class="error"><strong>Invalid Length:</strong> Your %s must not exceed %s characters</p>');
$this->validation->set_message('max_length', '<p class="error"><strong>Invalid Length:</strong> Your %s must be within %s characters</p>');
$this->validation->set_message('matches', '<p class="error"><strong>Passwords Don\'t Match:</strong> Please make sure your passwords are the same in both fields</p>');
$this->validation->set_rules($rules);
$fields['firstname'] = 'first name';
$fields['lastname'] = 'last name';
$fields['homephone'] = 'home phone';
$fields['mobilephone'] = 'mobile phone';
$fields['streetaddress'] = 'street address';
$fields['citystatezip'] = 'city, state. zip';
$fields['email'] = 'email address';
$this->validation->set_fields($fields);
// [END] Validation
if ($this->validation->run() == false) { // If the form doesn't validate
$this->template->load('template/default','/users/index', $data);
} else { // If the form does validate, create the account and login to it
$userdata = $this->input->post();
$userdata['password'] = $this->encrypt->encode($userdata['password']);
if($this->user->add_user($userdata)) { // If add user sucessfull, login and redirect
$this->_login('email',$userdata('email'),$this->input->post($password));
$this->redirect('users/account');
}
}
}
function _chekemail($str){
if($this->user_model->get_user('email',$str)){ return false; } else { return true; }
}
Model:
Code:
<?php
class User_model extends Model {
function User_model()
{
// Call the Model constructor
parent::Model();
}
function get_user($key,$value)
{
$query = $this->db->query("SELECT * FROM users WHERE ".$key."=".$value);
return $query->result();
}
function add_user()
{
foreach ($_POST as $key => $value) {
$this->$key = $value;
}
if($this->db->insert('users', $this)) { return true; }
}
function edit_user()
{
foreach ($_POST as $key => $value) {
$this->$key = $value;
}
$this->db->update('users', $this, array('id', $_POST['id']));
}
}
?>
Also this is my first CI app so if I'm doing anything in a pointless or not-suggested-way way please let me know.