Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Inserting data into two tables on user sign up Reply To: Inserting data into two tables on user sign up

#164336
__
Participant

the website has 3 different types of users however, I also have a table for each user group (so Designers, Developers & Employers) which holds profile information such as bios/avatars etc.

Are the three user types really so different that they need to be stored in different tables? This seems unlikely. Columns which are common to all users (I imagine that bios/avatars would be) should not be duplicated across different tables. In fact, if those fields are also unique per user, I would expect to find them in the same table as usernames and hashes.

Speaking of which,

I have a MySQL table for users which holds core information such as username, passwords etc.

I hope by “passwords,” you mean “hashes”…? Storing passwords in plain text is A Very Bad Thing.

What I would like to know is, how do you insert data into two tables on sign up

By using two SQL statements. When you have a situation like this, where multiple statements depend on each other’s success (i.e., if storing the user’s name fails, it makes no sense to try to store their bio), you should wrap them in a transaction for consistency.

and then link them so I can grab all the data for one user.

Your thought was correct; use joins when you retrieve the data. As @shaneisme said, you’d need to share your DB schema if you needed a more specific answer.