PHP未定义的索引错误与某些变量

时间:2013-01-11 02:31:36

标签: php html variables

  

可能重复:
  PHP: “Notice: Undefined variable” and “Notice: Undefined index”

您好我的问题与PHP有关并且能够回应工作。

背景信息:

我的Php版本是5.4.3

问题:

我的问题是我一直无法将数据从我的html表单传递到php脚本并让它运行。我可以输入文本并将其提交到html表单,但是当我将它提交到PHP脚本时,它不起作用。下一页只显示HTML或PHP未定义的索引错误消息。

我重置了我的wamp服务器,它解决了问题,只显示了html。但是,PHP未定义的索引错误继续发生。

未定义的索引错误发生在第8行(php代码的第一行。在打开php之后,我尝试创建变量)。

它唯一有效的时间是我将html表单中的名称设置为“vv”并将php表单中的发布数据设置为“vv”。 VV是随机选择的。

您可以提供任何帮助。非常感谢。

CODE:

HTML表格

<form method="post" action="report2.php">
        <label for="when">When did it happen</label>
        <input type="text" id="when" name="when" />
        <br />
        <input type="submit" value="submit" name="submit" />
</form>

PHP脚本

<body>
    <h1>Aliens Abducted Me - Report an Abduction</h1>
    <?php
        $when = $_POST['when'];

        echo 'You were abducted on ' . $when;
    ?>
</body>

1 个答案:

答案 0 :(得分:-1)

德鲁,

试试这个:

<?php
        $when = 'hello';

        echo $when;
?>

只是为了查看您的localhost是否正常工作。 还尝试免费的虚拟主机(PHP托管)来消除 您的本地服务器问题。

吉姆