unique always saying value already exists
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. 尝试这个 :-
$this->form_validation->set_rules('user', 'Username', 'trim|required|min_length[3]|max_length[20]|alpha_dash|unique[users.user]');
链接地址: http://www.djcxy.com/p/25158.html
上一篇: 合并angular和Django的url
下一篇: 独特总是说价值已经存在