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


Dave Faliskie
Dave Faliskie
17,793 Points

Using HTML form input with OOP in PHP

I am fairly new to PHP programing, today I finished the OOP basics in PHP. I was wondering if/how you could use html forms to create new objects using user input. I have not yet gotten to mySQL yet, so maybe that is how you would do this. I am trying to build a pretty advanced website and don't really know what to focus on learning next. If anyone has any advice on the order to learn languages please comment.

so far I know HTML, CSS, and some PHP.

4 Answers

To learn fast you should try to make some "projects". I did a craigslist copy and I really did dive in to PHP. In two weeks I was done and really comfortable with PHP and Databases (even if the website wasn't a 100% secure, but still learn a lot about security). I recommend MySQL or SQLite and always connect the databases with PDO class instad of the others because It's not depended on what database you're using.

When you're done you should make your own "micro framework" because you will mostly end up using a framework in the future and its really important in order to use one is to know how it works from the scratch. After, when you're really comfortable with PHP then you should dive in to a framework like Laravel (my recommendation) or any other. When you know all that stuff and created your own "micro framework" you will laugh how easy and fun it is to use an existing framework in PHP and other languages.

For any advanced website, you're likely going to need database interactivity, in which case you should definitely learn about MySQL next - it's an amazingly powerful tool, even more than i had originally thought when i started learning PHP and MySQL not too long ago.

I'm relatively new to objects myself, but it can work similarly to procedural PHP but using what you've learned on objects. You can take the input from a user, store it in a variable and use that variable within your object. Below is some code i've just written that seems to work fine.

class Worker {

    public function addWorker() {
        $this->name = $_POST['name'];


$worker = new Worker();
echo $_POST['name'];


<form method="post">
<input type="text" name="name">
<input type="submit" value="submit">

Maybe you should echo the object instead of the POST request for the usage of OOP :).

Dave Faliskie
Dave Faliskie
17,793 Points

Thanks Ill start learning mySQL next

Dave Faliskie
Dave Faliskie
17,793 Points

thanks, does tree house teach how to make a micro framework? is that part of mySQL?

I did check it out. Haven't yet seen it but this looks promising http://teamtreehouse.com/library/converting-an-html-site-to-a-php-micro-framework.

A framework is like a pre-written library to the language prepared with code you mostly use. For example when you start a database based project with php, you always end up with writing the same code over and over again for each project. With a framework most of the code is pre-written for you so you don't need to write "the basics" every time and it helps you keep following a good structure rule for you code.