HTML form POST to PHP page

ok ... i created a form.html page. It prompts the user for input in 6 text fields. POST form to a separate page called myform.php. The myform.php page just returns the values ​​entered by the user. However, when I click the submit button, I just get myform.php source code popping up on the screen.

<div class="content">
        <form action="myform.php" method="post">
            Name: <input name="name" type="text" size="25" />
            Course: <input name="course" type="text" size="25" />
            Book: <input name="book" type="text" size="255" />
            Price: <input name="price" type="text" size="7" />
            Email: <input name="email" type="text" size="255" />
            Phone #: <input name="phone" type="text" size="12" />

            <input name="mySubmit" type="submit" value="submit" />
        </form>
    </div>

<?php
$name = $_POST["name"];
$course = $_POST["course"];
$book = $_POST["book"];
$price = $_POST["price"];
$email = $_POST["email"];
$phone = $_POST["phone"];

?>
</head>

<body>
<?php
    echo $name;
    ?>
</body>

      

+3


source to share


2 answers


Mark Tetsler is right. You want the PHP extension page for PHP code to be rendered first. But I would suggest that you separate your form and form processing pages. I would suggest the following:

myform.php:

<!DOCTYPE html>
<html>
<head></head>
<body>   
<div class="content">
    <form action="formprocessor.php" method="POST">
        <label>Name: </label>
        <input name="name" type="text" size="25" />

        <label>Course: </label>
        <input name="course" type="text" size="25" />

        <label>Book: </label>
        <input name="book" type="text" size="255" />

        <label>Price: </label>
        <input name="price" type="text" size="7" />

        <label>Email: </label>
        <input name="email" type="text" size="255" />

        <label>Phone #: </label>
        <input name="phone" type="text" size="12" />

        <input name="mySubmit" type="submit" value="Submit!" />
    </form>
</div>
</body>
</html>

      



formprocessor.php:

<?php
$name = $_POST["name"];
$course = $_POST["course"];
$book = $_POST["book"];
$price = $_POST["price"];
$email = $_POST["email"];
$phone = $_POST["phone"];

echo $name;
?>

      

+6


source


Your big problem is in your first sentence

ok ... i created a form.html page



To run PHP code on your server, you need to rename the form.php file, unless you have combined both files in your sample code.

+2


source







All Articles