[Solved] When Insert New User Get 2 preg_match() errors |
[eluser]riwakawd[/eluser]
I don't know why I am getting 2 errors some array issue which I am not sure of does not give the error on register model on codeigniter? Error 1 A PHP Error was encountered Severity: Warning Message: preg_match() expects parameter 2 to be string, array given Filename: mysql/mysql_driver.php Line Number: 199 Error 2 A PHP Error was encountered Severity: Warning Message: preg_match() expects parameter 2 to be string, array given Filename: database/DB_driver.php Line Number: 622 Code: public function insert_user() {
[eluser]riwakawd[/eluser]
Please note: I worked it out I had to make some changes. Here below is what have changed. Now just have to find away to make new user have own user id. Code: public function insert_user() {
[eluser]Tim Brownlaw[/eluser]
Hi, When you perform an insert, using $this->db->insert_id() will return the value of the newly created primary key. Which is normally an auto incrementing integer... So if you use an id as your primary key as your members id, that should work out for you. cheers Tim
[eluser]riwakawd[/eluser]
[quote author="Tim Brownlaw" date="1398753608"]Hi, When you perform an insert, using $this->db->insert_id() will return the value of the newly created primary key. Which is normally an auto incrementing integer... So if you use an id as your primary key as your members id, that should work out for you. cheers Tim[/quote] I have on my sql both user and id as int. but trying now to get the user id have the same as id. Are you saying to put AUTO_INCREMENT every thing else is working but not the user_id just trying to get that the same when user registers. If you know what I mean. Code: CREATE TABLE IF NOT EXISTS `users` (
[eluser]Tim Brownlaw[/eluser]
Well in this... Code: `id` int(11) NOT NULL AUTO_INCREMENT, The id is your unique id which would be your user id... There isn't any point in having both... So you could loose the id and rename it to user_id Code: `user_id` int(11) NOT NULL AUTO_INCREMENT, or just have id as your user id Code: `id` int(11) NOT NULL AUTO_INCREMENT, you'll be using the user_id as a foreign key to any other tables so if you like to have them all the same name across tables use user_id as your primary key Code: CREATE TABLE IF NOT EXISTS `users` ( So you don't need to have an id and a user_id... Choose one or the other! Cheers Tim
[eluser]riwakawd[/eluser]
[quote author="Tim Brownlaw" date="1398755351"]Well in this... Code: `id` int(11) NOT NULL AUTO_INCREMENT, The id is your unique id which would be your user id... There isn't any point in having both... So you could loose the id and rename it to user_id Code: `user_id` int(11) NOT NULL AUTO_INCREMENT, or just have id as your user id Code: `id` int(11) NOT NULL AUTO_INCREMENT, you'll be using the user_id as a foreign key to any other tables so if you like to have them all the same name across tables use user_id as your primary key Code: CREATE TABLE IF NOT EXISTS `users` ( So you don't need to have an id and a user_id... Choose one or the other! Cheers Tim[/quote] Ok Will do it that way.
[eluser]riwakawd[/eluser]
[quote author="Tim Brownlaw" date="1398755351"]Well in this... Code: `id` int(11) NOT NULL AUTO_INCREMENT, The id is your unique id which would be your user id... There isn't any point in having both... So you could loose the id and rename it to user_id Code: `user_id` int(11) NOT NULL AUTO_INCREMENT, or just have id as your user id Code: `id` int(11) NOT NULL AUTO_INCREMENT, you'll be using the user_id as a foreign key to any other tables so if you like to have them all the same name across tables use user_id as your primary key Code: CREATE TABLE IF NOT EXISTS `users` ( So you don't need to have an id and a user_id... Choose one or the other! Cheers Tim[/quote] I have it all working now register side of things done cheers all for help. Finally also got date helper worked out. Talk to you soon,
[eluser]InsiteFX[/eluser]
The only time you need other id's is if your referencing another table. |
Welcome Guest, Not a member yet? Register Sign In |