【问题标题】:$_POST superglobal not passing (1and1)$_POST 超全局不通过 (1and1)
【发布时间】:2011-03-20 02:19:36
【问题描述】:

我刚刚制作了一个基本的表单页面,通过 Aptana、WAMP 和一个基本的 1and1 托管页面,我无法让表单字段通过 $_POST 超全局。

这里是 index.html 页面:

<html>
<head>
    </head>
    <body>
        <p>Type in the areas</p>
    <form action="keywords.php" method="POST">
        <label for="Area1"> 1:</label>
        <input type="text" id="Area1" name="first area /"><br />
        <label for="Area1"> 2:</label>
        <input type="text" id="Area2" name="second area /"><br />
        <label for="Area1"> 3:</label>
        <input type="text" id="Area3" name="third area /"><br />
        <label for="Area1"> 4:</label>
        <input type="text" id="Area4" name="fourth area /"><br />
        <label for="Area1"> 5:</label>
        <input type="text" id="Area5" name="fifth area /"><br />
        <label for="Area1"> 6:</label>
        <input type="text" id="Area6" name="sixth area /"><br />
        <label for="Area1"> 7:</label>
        <input type="text" id="Area7" name="seventh area /"><br />
        <label for="Area1"> 8:</label>
        <input type="text" id="Area8" name="eighth area /"><br />
            <input type="submit" value="Run" name="Run">
            </form>
    </body>
</html>
?>

传递给keywords.php

<?php

 if(isset($_POST['submit'])){
     echo "test";


    $area1 = $_POST['Area1'];
    $area2 = $_POST['Area2'];
    $area3 = $_POST['Area3'];
    $area4 = $_POST['Area4'];
    $area5 = $_POST['Area5'];
    $area6 = $_POST['Area6'];
    $area7 = $_POST['Area7'];
    $area8 = $_POST['Area8'];


    echo $area1;
 }
 ?>

亲爱的主,我做错了什么。要温柔。 PHP 5.3.4

【问题讨论】:

    标签: php superglobals


    【解决方案1】:

    变量根据名称插入$_POST。所以应该是$_POST['first area']

    另外,我不知道这是否是错误的复制,但名称内不应该有斜线......它们应该在引号之外。例如:

    <input type="text" id="Area1" name="first area" /><br />
    

    【讨论】:

      【解决方案2】:

      错误,在您的 PHP 代码中,您指的是您在 HTML id 属性中给出的值,而不是表单元素的 name 属性。浏览器将 name 属性作为表单元素的名称传递。试试 $_POST['first area'] 等 :)

      【讨论】:

        【解决方案3】:

        您实际上可以将所有输入作为一个数组传递。

        这是一个例子。

        <html>
        <head>
            </head>
            <body>
                <p>Type in the areas</p>
            <form action="keywords.php" method="POST">
                <label for="Area1"> 1:</label>
                <input type="text" id="Area1" name="area[]"><br />
                <label for="Area1"> 2:</label>
                <input type="text" id="Area2" name="area[]"><br />
                <label for="Area1"> 3:</label>
                <input type="text" id="Area3" name="area[]"><br />
                <label for="Area1"> 4:</label>
                <input type="text" id="Area4" name="area[]"><br />
                <label for="Area1"> 5:</label>
                <input type="text" id="Area5" name="area[]"><br />
                <label for="Area1"> 6:</label>
                <input type="text" id="Area6" name="area[]"><br />
                <label for="Area1"> 7:</label>
                <input type="text" id="Area7" name="area[]"><br />
                <label for="Area1"> 8:</label>
                <input type="text" id="Area8" name="area[]"><br />
                    <input type="submit" value="Run" name="Run">
                    </form>
            </body>
        </html>
        

        会给你一个变量:$_POST['area'] 这个变量是一个 8 值数组,然后你可以迭代。

        【讨论】:

          猜你喜欢
          • 2017-01-07
          • 2013-11-15
          • 2018-06-23
          • 1970-01-01
          • 1970-01-01
          • 2021-09-09
          • 2018-02-26
          • 2013-04-21
          相关资源
          最近更新 更多