CodeIgniter is_unique always says value already exists

I use CodeIgniter form validation, and I spent a lot of time trying to fix this, no luck. I have this field:

<input type="text" name="user" id="user" length="20" placeholder="Username"> 

And I use this to check:

 $this->form_validation->set_rules('user', 'Username', 'trim|required|min_length[3]|max_length[20]|alpha_dash|is_unique[users.user]'); 

My db has a users table and user is a field in it, so I don't know what I'm doing wrong, or what the problem is. The table is empty (but I also tried to have entries with it), and the " unique " icon was selected in phpmyadmin. I know that the db connection works fine, because if I delete this rule and enter other valid data and submit the form, the user will be added to the database.

If is_unique uses a different db configuration file, which I did not configure? I really do not know. This is frustrating, and I think I can just refuse to use the framework ...

Your help will be wonderful! Thanks.

+7
php mysql validation forms codeigniter
source share
4 answers

This may / may not help: it seems you will load the DB after by doing a form check. There is also a typo uses.user .

+1
source share

In Transact-SQL, the word "USER" is a special word. Try using use.user with reverse ticks:

 `users.user` 
... see if that helps.
+1
source share

try the following: -

 $this->form_validation->set_rules('user', 'Username', 'trim|required|min_length[3]|max_length[20]|alpha_dash|unique[users.user]'); 
+1
source share

he needs to load the database.

 $this->load->database(); 
0
source share

All Articles