douchengjue9892 2013-01-11 02:31
浏览 54

PHP未定义的索引错误与某些变量[重复]

Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”

Hi my question relates to PHP and getting echo to work.

Background info:

My Php version is 5.4.3

Problem:

My problem is that I have been having trouble passing data from my html form to a php script and getting it to run. I can enter and submit text into the html form, but when I submit it to the PHP script it doesn't work. The next page either just displays HTML or a PHP undefined index error message.

I reset my wamp server and it solved the issue with only the html was being displayed. However, the PHP undefined index error continues to occur.

The undefined index error occurs on line 8 (the first line of the php code. right after the opening php where i try to create the variable).

The only time it works is when I set name in the html form to "vv" and set the post data in the php form to "vv". VV was selected totally at random.

Any help you can provide would be MUCH appreciated.

CODE:

HTML FORM

<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 Script

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

        echo 'You were abducted on ' . $when;
    ?>
</body>
  • 写回答

1条回答 默认 最新

  • douba1904 2013-01-11 02:42
    关注

    Drew,

    Try this:

    <?php
            $when = 'hello';
    
            echo $when;
    ?>
    

    Just to see if your localhost is working. Also try a free web hosting (php hosting) to eliminate your local server issue.

    Jim

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献