Page 1 of 1

Adding User and Data to Database when user logs in.

Posted: Sat Sep 08, 2012 8:36 pm
by Scotty1207
I know the title is long but it's not really long enough to describe what I need help with. I'm working on a little site which uses the SMF SSI.php method of using the SMF Forums user details for the login, so my users don't have to create another account. However I want to on the first time the user logs into the site to have their username to be entered into a different database which has other fields to hold information which the user can then edit on the profile page of my site. However I'm new to PHP and was wondering if someone could point me in the right direction.

Thanks,

Scott

Re: Adding User and Data to Database when user logs in.

Posted: Sun Sep 09, 2012 7:44 pm
by jacek
You basically want a simple INSERT

[syntax=sql]INSERT INTO `table` (`user_name`, `some`, `other`, `columns`)
VALUES ('{$username}', 'some', 'other', 'values')[/syntax]

If the table is actually in another database you will have to specify that

[syntax=sql]INSERT INTO `database`.`table` (`user_name`, `some`, `other`, `columns`)
VALUES ('{$username}', 'some', 'other', 'values')[/syntax]

Re: Adding User and Data to Database when user logs in.

Posted: Sun Sep 09, 2012 7:49 pm
by Scotty1207
Ok thanks, is it possible to only execute this if the user logs in for the first time or does it not matter because I will want to add aditional data to that user through various forms on my site.

Re: Adding User and Data to Database when user logs in.

Posted: Sun Sep 09, 2012 7:52 pm
by jacek
You would have to store a flag in the main table to show that it was their first login so it would go a bit like this

1. User registers, set column `first_login` = 1
2. User logs in, check if (`first_login` == 1) if it does insert the new row and set `first_login` to 0

Re: Adding User and Data to Database when user logs in.

Posted: Sun Sep 09, 2012 7:58 pm
by Scotty1207
Ok thanks I'll give it a try