Adding User and Data to Database when user logs in.

Ask about a PHP problem here.
Post Reply
Scotty1207
Posts: 7
Joined: Wed Apr 11, 2012 5:45 pm

Adding User and Data to Database when user logs in.

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post by jacek »

You basically want a simple INSERT
INSERT INTO `table` (`user_name`, `some`, `other`, `columns`)
VALUES ('{$username}', 'some', 'other', 'values')
If the table is actually in another database you will have to specify that
INSERT INTO `database`.`table` (`user_name`, `some`, `other`, `columns`)
VALUES ('{$username}', 'some', 'other', 'values')
Image
Scotty1207
Posts: 7
Joined: Wed Apr 11, 2012 5:45 pm

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

Post 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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

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

Post 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
Image
Scotty1207
Posts: 7
Joined: Wed Apr 11, 2012 5:45 pm

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

Post by Scotty1207 »

Ok thanks I'll give it a try
Post Reply