HTML表单POST到PHP页面 [英] HTML Form POST to PHP page

查看:141
本文介绍了HTML表单POST到PHP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的...我创建了一个form.html页面。它要求用户输入6个文本字段。表单POST到一个名为myform.php的单独页面。 myform.php页面只是返回用户输入的值。但是,当我点击提交时,我只是在屏幕上弹出myform.php源代码。

 < div class =content> 
< form action =myform.phpmethod =post>
名称:< input name =nametype =textsize =25/>
课程:< input name =coursetype =textsize =25/>
Book:< input name =booktype =textsize =255/>
价格:< input name =pricetype =textsize =7/>
电子邮件地址:< input name =emailtype =textsize =255/>
电话号码:< input name =phonetype =textsize =12/>

< input name =mySubmittype =submitvalue =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>


解决方案

Marc Towler是正确的。您需要首先解析PHP代码的PHP扩展页面。但我实际上建议你将表单的页面和表单处理分开。我建议如下:

myform.php:

  <!DOCTYPE html> 
< html>
< head>< / head>
< body>
< div class =content>
< form action =formprocessor.phpmethod =POST>
< label>名称:< / label>
< input name =nametype =textsize =25/>

< label>课程:< / label>
< input name =coursetype =textsize =25/>

< label>书:< / label>
< input name =booktype =textsize =255/>

< label>价格:< / label>
< input name =pricetype =textsize =7/>

< label>电子邮件:< / label>
< input name =emailtype =textsize =255/>

< label>电话号码:< / label>
< input name =phonetype =textsize =12/>

< input name =mySubmittype =submitvalue =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;
?>


ok...i created a form.html page. It asks the user to input into 6 text fields. The form POSTs to a separate page called myform.php. The myform.php page simply just returns the values the user entered. However, when I click submit I just get the 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>

解决方案

Marc Towler is correct. You need to have the page with the extension of PHP for PHP code to be parsed in the first place. But I'd actually suggest you separate the pages of your form and your form processing. I'd 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;
?>

这篇关于HTML表单POST到PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆