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 Basic PHP Website (2018) Adding a Basic Form HTML Forms

how do I handle this .The code below contains a simple HTML form. It looks fine in the browser, but it does not send the

<html> <head> <title>Ye Olde Ice Cream Shoppe</title> </head> <body>

<p>Your order has been created. What flavor of ice cream would you like to add to it?</p>

<form>

<?php

    <label for="flavor">Flavor</label>
    <select id="flavor">
        <option value="">&#8212; Select &#8212;</option>
        <option value="Vanilla">Vanilla</option>
        <option value="Chocolate">Chocolate</option>
        <option value="Strawberry">Strawberry</option>
        <option value="Cookie Dough">Cookie Dough</option>
    </select>

    <input type="submit" value="Update Order">

?> </form>

</body> </html>

index.html
<?php
<html>
<head>
    <title>Ye Olde Ice Cream Shoppe</title>
</head>
<body>

    <p>Your order has been created. What flavor of ice cream would you like to add to it?</p>

    <form>
<?php

        <label for="flavor">Flavor</label>
        <select id="flavor">
            <option value="">&#8212; Select &#8212;</option>
            <option value="Vanilla">Vanilla</option>
            <option value="Chocolate">Chocolate</option>
            <option value="Strawberry">Strawberry</option>
            <option value="Cookie Dough">Cookie Dough</option>
        </select>

        <input type="submit" value="Update Order">
?>
    </form>

</body>
</html>
?>

2 Answers

Andy Watts
Andy Watts
20,836 Points

A form tag needs an action method. An action method tells the browser, where to send the data that the user filled in. It could go to the same page or it can go to a different page.

<form action="process.php">
 /*form here*/
</form>
jason chan
jason chan
31,009 Points

you have to use a form action. You only need to know two. Post and get.

http://php.net/manual/en/tutorial.forms.php

http://php.net/manual/en/reserved.variables.get.php

Post to database. Get to read the data from database.

GL.