I'm using CodeIgniter's form validation, and I've spent a lot of time trying to fix this, with no luck. I have this field:
<input type="text" name="user" id="user" length="20" placeholder="Username">
And I'm using this to validate:
$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 table users
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've also tried with it having records) and in phpmyadmin the "unique
" icon is selected.
I know the db connection is working fine, because if I remove that rule and enter otherwise valid data and submit the form, then the user is added to the database.
Unless is_unique uses another db configuration file that I haven't configured? I don't really know. It's kind of frustrating and I'm thinking that I may as well just drop the use of a framework...
Your help would be great! Thanks.
This might/might not help: You seem to be loading the DB after running the form validation. There's also a typo uses.user
.
In Transact-SQL the word "USER" is a special word. Try surrounding uses.user with a back-ticks like so:
`users.user`
...see if that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With