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

PHP Build a Simple PHP Application Adding a Contact Form Form Submissions

Alec Jones
Alec Jones
5,510 Points

What goes at the end?

The $_GET array contains variables added to the web address. If I want my first name (Randy) displayed by this PHP command ...

echo $_GET["name"];

ā€¦ then what needs to be added to the end of the web address?

http://localhost/contact-thanks.php ________

What goes there?

2 Answers

The URL encoded variable for name. I have been trying to think of a way to explain this without just giving the answer, but I dont think there is a good way to do that, haha.

    http://localhost/contact-thanks.php?name=Randy

So as you can see there, after the .php you can place a "?" and any variables you want to pass to the PHP code. In this case you are passing the key "name" with the value "Randy"

To expand a little on that, you can also add on more variables by separating them with an "&" like:

http://localhost/contact-thanks.php?name=Randy&favoriteFlavor=vanilla&favoriteColor=blue

so in the php you have access to 3 GET variables:

    echo $_GET["name"];
    echo $_GET["favoriteFlavor"];
    echo $_GET["favoriteColor"];

To expand a little on that, you can also add on more variables by separating them with an "&" like:

http://localhost/contact-thanks.php?name=Randy&favoriteFlavor=vanilla&favoriteColor=blue

so in the php you have access to 3 GET variables:

    echo $_GET["name"];
    echo $_GET["favoriteFlavor"];
    echo $_GET["favoriteColor"];