I've created a modal register form and when i submit the form i get the following error:
Code:
jquery-3.3.1.min.js:2
POST http://localhost/[website_name]/users/create_user 500 (Internal Server Error)
I've checked the controller and model and i cant find any errors.
Any ideas?!
Controller
Code:
public function create_user(){
$email = trim( $this->input->post('email') );
$email_exist = $this->user_model->check_email_exist($email);
if ($email_exist) {
$result['status'] = 'failed';
$result['message'] = $this->lang->line('error_email_exist');
} else {
//Pass enc
$enc_password = md5($this->input->post('passInput'));
$register = $this->user_model->register($enc_password);
if ($register) {
$result['status'] = 'success';
} else {
$result['status'] = 'failed';
$result['message'] = 'Please fill all the fields';
}
}
return json_encode($result);
}
Model
Code:
public function register($enc_password){
$user_name = convert_accented_characters($this->input->post('screenNameInput'));
$user_name_slug = url_title($user_name);
$data = array();
$data['user_group_id'] = $this->input->post('userGroupInput');
$data['screen_name'] = $this->input->post('screenNameInput');
$data['username'] = $this->input->post('usernameInput');
$data['email'] = $this->input->post('email');
$data['password'] = $enc_password;
$data['slug'] = $user_name_slug;
$data['register_status'] = 1;
$data['unique_id'] = random_string('numeric', 6);
if ( $this->input->post('userGroupInput') == 1 && $this->input->post('websiteInput') ) {
$data['website'] = $this->input->post('websiteInput');
}
$this->db->insert('users', $data);
$user_id = $this->db->insert_id();
$contact_data = array(
'primary_num' => $this->input->post('phoneInput'),
'info_group_name' => $this->input->post('screenNameInput'),
'city' => $this->input->post('cityInput'),
'to_user_id' => $user_id
);
$registered = $this->db->insert('contact_info', $contact_data);
if ($registered) {
return true;
} else {
return false;
}
}
Ajax function:
Code:
$('#userRegister').on('submit', function(e){
e.preventDefault();
var form = $(this);
$.ajax({
url: form.attr('action'),
type: "POST",
data: form.serialize(),
dataType: "json",
success: function(data){
if(data.status == 'success') {
window.location.href = 'users';
} else if (data.status == 'failed' ) {
$('.error-messages').html(data.message);
$('.error-messages').fadeIn('fast');
setTimeout(function(){
$('.error-messages').fadeOut('fast');
}, 2000);
}
}
});
});
//Life motto
if (sad() == true) {
sad().stop();
develop();
}