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


Storing data from form elements

Hey everyone,

What's the best way to store data from html form elements? Do I need a database like SQL running on the same server as my site, or can I export labeled form data via email or text file?

Any tips or best practices are appreciated.


3 Answers

Chris Dziewa
Chris Dziewa
17,781 Points

Reid, it depends what you would like to do with the data. If you keep going in the PHP courses, Randy will explain how to send the data in the $_POST variable. In general, I don't think you would want a public facing form connecting to your database, unless of course you were creating a user registration/login system, then there is a lot involved including sanitizing input (should be used for regular forms anyway-just more important when involving databases) and hashing or encrypting data for security concerns.

If all you want to do is use the information to send an email, you could do this with the $_POST variable.

I'll be checking out the PHP courses today. Thanks, Chris!

What about collecting private data and populating a database of some sort? For a contact form, your answer is great. For capturing data from potential clients, I'd like to keep everything hidden.

Chris Dziewa
Chris Dziewa
17,781 Points

I guess it comes down to what would you like to do with the data once you have it? The post variable will allow you to use the $_POST variable for email plugins to send yourself data. This isn't shown on the page, though I'm sure there are ways to sniff the information from the server if someone really knew what they were doing.

I'm not familiar with authorization in PHP but in Ruby on Rsils you can actually use gem addons like devise for having user registration and logins. Once that person has been granted access, you could allow them privileges. If you want to make your own authorization system, learn about hashing data for database storage as well as hash salts.

I'm sure there must be some type of authorization capabilities in PHP and maybe using a PHP framework could expedite making such a system. In the third course of PHP, databases are used, but only to retrieve information that was stored when the database was created.

I think you may enjoy Ruby once you have finished the PHP track. Also, I learned about hashing and creating salts from Udacity though it requires you to learn Python which is very similar to Ruby. Hope this points you in the right direction!