Note that there are some explanatory texts on larger screens.

plurals
  1. PONot returning desired error/success message
    primarykey
    data
    text
    <p>For some reason when I submit my form what gets submitted back is "There was a problem creating the user! Please try again!" but it still makes a new database entry and I'm not sure why. I'm running tests on my form but with the data I'm submitting it should be giving me a success message. Any ideas?</p> <p>EDIT: I've tried for 2 days now and still can't seem to figure this out.</p> <p><strong>Controller:</strong></p> <pre><code>function register_submit() { $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric|strtolower'); $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'trim|required|xss_clean|valid_email'); $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric'); $this-&gt;form_validation-&gt;set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean|matches[password]|min_length[6]|max_length[12]|alpha_numeric'); $this-&gt;form_validation-&gt;set_rules('first_name', 'First Name', 'trim|required|xss_clean|alpha'); $this-&gt;form_validation-&gt;set_rules('last_name', 'Last Name', 'trim|required|xss_clean|alpha'); if (!$this-&gt;form_validation-&gt;run()) { echo json_encode(array('error' =&gt; 'yes', 'message' =&gt; 'There was a problem submitting the form! Please refresh the window and try again!')); } else { $user_data = $this-&gt;kow_auth-&gt;create_user($this-&gt;input-&gt;post('username'), $this-&gt;input-&gt;post('email'), $this-&gt;input-&gt;post('password'), $this-&gt;input-&gt;post('first_name'), $this-&gt;input-&gt;post('last_name')); if ($user_data == FALSE) { echo json_encode(array('error' =&gt; 'yes', 'message' =&gt; 'There was a problem creating the user! Please try again!')); } else { $data['activation_period'] = 48; $this-&gt;kow_auth-&gt;send_email('activate', $data['email'], $data); unset($data['password']); echo json_encode(array('sucess' =&gt; 'yes', 'message' =&gt; 'You have successfully registered. Check your email address to activate your account!')); } } } </code></pre> <p><strong>Library:</strong></p> <pre><code>/** * Create new user on the site and return some data about it: * user_id, username, password, email, new_email_key (if any). * * @param string * @param string * @param string * @param string * @param string * @return array */ function create_user($username, $email, $password, $first_name, $last_name) { if ((strlen($username) &gt; 0) AND !$this-&gt;ci-&gt;users-&gt;is_username_available($username)) { return FALSE; } elseif (!$this-&gt;ci-&gt;users-&gt;is_email_available($email)) { return FALSE; } else { $genPassHash = $this-&gt;ci-&gt;genfunc-&gt;GenPassHash($password); $max_user_id = $this-&gt;ci-&gt;users-&gt;get_max_users_id(); $data = array( 'username' =&gt; $username, 'password' =&gt; $genPassHash[0], 'password2' =&gt; $genPassHash[1], 'email' =&gt; $email, 'first_name' =&gt; $first_name, 'last_name' =&gt; $first_name, 'new_email_key' =&gt; md5(rand().microtime()), 'user_id' =&gt; $max_user_id, 'ip_address' =&gt; $this-&gt;ci-&gt;input-&gt;ip_address() ); if (($result = $this-&gt;ci-&gt;users-&gt;create_user($data)) == FALSE) { $data['user_id'] = $res['user_id']; $data['password'] = $password; unset($data['last_ip']); return $data; } } return FALSE; } </code></pre> <p><strong>Users Model:</strong></p> <pre><code>/** * Create new user record * * @param array * @return bool */ function create_user($data) { $data['date_created'] = date('Y-m-d H:i:s'); $this-&gt;db-&gt;set('username', $data['username']); $this-&gt;db-&gt;set('password', $data['password']); $this-&gt;db-&gt;set('password2', $data['password2']); $this-&gt;db-&gt;set('email', $data['email']); $this-&gt;db-&gt;set('first_name', $data['first_name']); $this-&gt;db-&gt;set('last_name', $data['last_name']); $this-&gt;db-&gt;set('ip_address', $data['ip_address']); $this-&gt;db-&gt;set('date_created', $data['date_created']); $query = $this-&gt;db-&gt;insert('users'); if ($query) { return TRUE; } else { return FALSE; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload