Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,008 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.