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!
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

Charles Hedricks
3,149 PointsUser input to table, then post to MySQL database - best option.
I have a HTML form with an imbedded table set up to collect customer information for name, address (2 lines), city, state, zip, phone and email. The customer views the online form on my contact page and selectively inputs data to each field then submits via the regular submit button process when completed.
I am looking for best practices in filtering or validating and sanitizing the data before posting to the MySQL database, also - how the data would be organized when exported from the table to the MySQL input.
Also - flashing a message when the data was successfully posted to the MySQL server.
To this point I have not found a good discussion or video that would point me in the right direction, looking for assistance if possible.
Thanks in advance.

Karim Vally
646 PointsYou can use HTML attributes such as type="email" in text boxes to validate whether an email is correctly formatted. However their are some issues with this as the type attribute is not supported on a few browsers.
I think since you're using PHP your best option is to use regular expressions? Perhaps if you want to hardcode it yourself use IF statements? Ofcourse you want to validate input before inserting rows into the DB so for example, you have a drop down list called 'state' its default selected value is "" and its field to display is "Select your state" perhaps change the value to 1, then you can do something like this:
if($_POST["state"] == 1) { // Display message here }
Charles Hedricks
3,149 PointsCharles Hedricks
3,149 PointsThis is my current code: