Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i stop duplicate entries going into my membership database?
    primarykey
    data
    text
    <p>I am using the form validation functionality — it currently doesn't allow a user to enter incorrect username and password parameters when creating an account. But it's meant to bounce the user back to the signup screen. Instead they're brought through to the home screen, and if I use a username that's been used before it goes into the database anyway.</p> <p>Signup controller:</p> <pre><code>class Signup extends CI_Controller { function Signup() { parent::__construct(); $this-&gt;load-&gt;model('membership'); } function index() { $this-&gt;load-&gt;view('shared/header'); $this-&gt;load-&gt;view('account/signuptitle'); $this-&gt;load-&gt;view('account/signupview'); $this-&gt;load-&gt;view('shared/footer'); } function register() { $this-&gt;load-&gt;helper(array('form', 'url')); $this-&gt;load-&gt;library('form_validation'); $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|trim'); $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required|md5|trim'); $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'callback_usernameTaken'); $username = $this-&gt;input-&gt;post('username'); $password = $this-&gt;input-&gt;post('password'); if ($this-&gt;form_validation-&gt;run()) { $this-&gt;membership-&gt;newUser($username, $password); $this-&gt;session-&gt;set_userdata('status', 'OK'); $this-&gt;session-&gt;set_userdata('username', $username); redirect('home'); } if ($this-&gt;membership-&gt;usernameTaken($username)) { $this-&gt;load-&gt;view('shared/header'); $this-&gt;load-&gt;view('account/signuptitle'); $this-&gt;load-&gt;view('account/signupview'); $this-&gt;load-&gt;view('shared/footer'); } else { $this-&gt;load-&gt;view('shared/header'); $this-&gt;load-&gt;view('account/signuptitle'); $this-&gt;load-&gt;view('account/signupview'); $this-&gt;load-&gt;view('shared/footer'); } } } </code></pre> <p>I think the <code>if ($this-&gt;membership-&gt;usernameTaken($username))</code> statement needs to arranged a certain way could it possibly be an else if statement?</p> <p>Membership Model:</p> <pre><code>class Membership extends CI_Model { function Membership() { parent::__construct(); } function newUser($username, $password) { $newMember = array('username' =&gt; $username, 'password' =&gt; $password); $insert = $this-&gt;db-&gt;insert('membership', $newMember); } function usernameTaken($username) { $this-&gt;db-&gt;select('*')-&gt;from('membership')-&gt;where('username', $username); $query = $this-&gt;db-&gt;get(); if ($query-&gt;num_rows &gt; 0) { return true; } else { return false; } } </code></pre> <p>Thanks for the help again folks — I've been looking at similar issues on this site but I just found them too confusing</p>
    singulars
    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