doushangan3690 2013-10-26 14:44
浏览 75
已采纳

测试时PHP中的未定义索引错误

I have a minor problem. When I use this code:

<!DOCTYPE HTML>

<html>
    <head>
        <title>Declare Nerf War!</title>
    </head>
    <body>
        <?php
        $form="<center><form action='decwargen.php' method='POST'>
            Your Name: <input type='text' name='yname' placeholder='John Doe'><br>
            Opponent's Name: <input type='text' name='oname' placeholder='Jane Doe'><br>
            Why? <input type='text' name='why' placeholder='for stealing my stuff'><br>
            Date of war: <input type='text' name='dwar' placeholder='10/11/13'><br>
            Time of war: <input type='text' name='twar' placeholder='10:56 PM'><br>
            Created on: <input type='text name='crtd' placeholder='10/10/13'><br>
            <input type='submit' name='subbut' value='Submit'></center>
        </form>";
        $ok = $_POST ['subbut'];
        if($ok){
            $yname = $_POST ['yname'];
            $oname = $_POST ['oname'];
            $why = $_POST ['why'];
            $dwar = $_POST ['dwar'];
            $twar = $_POST ['twar'];
            $created = $_POST ['crtd'];
            echo("<center><h1>Declaration of war</h1><br><p contenteditable='true'>I, " . $yname . " declare war on " . $oname . " for/because " . $why . ". This will happen on " . $dwar . " at " . $twar . ".<br>Created on" . $created);
        } else echo($form);
        ?>
    </body>
</html>

The web browser says:

Notice: Undefined index: subbut in /Applications/MAMP/htdocs/decwargen.php on line 17

when I first go to the page, then

Notice: Undefined index: crtd in /Applications/MAMP/htdocs/decwargen.php on line 24

when I enter data. Can anyone please help?

  • 写回答

4条回答 默认 最新

  • dongpao1905 2013-10-26 14:47
    关注

    Change your

     <input type='text name='crtd' placeholder='10/10/13'>
              -------^ quote not closed properly
    

    to

    <input type='text' name='crtd' placeholder='10/10/13'>
    

    From your recent question edit, also make the following change:

    Replace your

    $ok = $_POST ['subbut'];
            if($ok){
    

    to

    if(isset($_POST ['subbut']))
            {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug