Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Help (again)!

Hi, I need to add the same data from a form input into two different tables does anyone have any idea how I can do this?

6 Answers

Coco Jackowski
Coco Jackowski
12,914 Points

Do you have a code example for things you've tried? Also, are you trying to do this using server-side form processing (ie in PHP or Ruby), or with JavaScript?

PHP, I think I might have to use the join statement but I don't know how the join statement works.

Coco Jackowski
Coco Jackowski
12,914 Points

When you say 'tables,' you're referring to database tables, then? It wasn't clear whether you were referring to an HTML table, which is why I asked if you were using client-side JavaScript. (Again, a code example would be very, very helpful. Also a more descriptive question for the title. ;D)

The simplest beginner-level solution would be to run two queries, I think. Just use the same variable (whatever data you got from the form) in one INSERT query, run it, then put the same variable into a second INSERT query and run that one.

Okay, thank you.

Two insert queries are the way to go, but may i ask why you want duplicate data in the same database?

Wouldn't that just make it bloated? and if an update to the data is required it adds an extra table to update the workload

As mentioned in your comment you might want to look at join, likeley an Inner Join, what you'd then do is have two sets of data with different columns joined on a key usually an id column

I am creating a custom blog and I need to add a title of the blog to the post information and then the title needs to go to the category tables.