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

测试时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?

图片转代码服务由CSDN问答提供 功能建议

我有一个小问题。 当我使用此代码时:

 &lt;!DOCTYPE HTML&gt; 
 
&lt; html&gt; 
&lt; head&gt; 
&lt; title&gt;宣布Nerf War!&lt;  ; / title&gt; 
&lt; / head&gt; 
&lt; body&gt; 
&lt;?php 
 $ form =“&lt; center&gt;&lt; form action ='decwargen.php'method ='POST'&gt;  
您的姓名:&lt; input type ='text'name ='yname'placeholder ='John Doe'&gt;&lt; br&gt; 
对手的名字:&lt; input type ='text'name ='oname'eplaceholder =  'Jane Doe'&gt;&lt; br&gt; 
为什么?&lt; input type ='text'name ='why'placeholder ='for stealing my stuff'&gt;&lt; br&gt; 
战争日期:&lt;输入 type ='text'name ='dwar'placeholder = '10 / 11/13'&gt;&lt; br&gt; 
战争时间:&lt; input type ='text'name ='twar'placeholder = '10:56  PM'&gt;&lt; br&gt; 
创建于:&lt; input type ='text name ='crtd'placeholder = '10 / 10/13'&gt;&lt; br&gt; 
&lt; input type ='submit'  name ='subbut'value ='Submit'&gt;&lt; / center&gt; 
&lt; / form&gt;“; 
 $ ok = $  _POST ['subbut']; 
 if($ ok){
 $ yname = $ _POST ['yname']; 
 $ oname = $ _POST ['oname']; 
 $ why = $ _POST [' 为什么']; 
 $ dwar = $ _POST ['dwar']; 
 $ twar = $ _POST ['twar']; 
 $ created = $ _POST ['crtd']; 
 echo(“&lt;  center&gt;&lt; h1&gt;战争宣言&lt; / h1&gt;&lt; br&gt;&lt; p contenteditable ='true'&gt; I,“。  $ yname。  “宣战”。  $ oname。  “为/因为”。  $ why。  “这将发生在”。  $ dwar。  “ 在 ” 。  $ twar。  “。&lt; br&gt;创建于”。  $ created ;; 
} else echo($ form); 
?&gt; 
&lt; / body&gt; 
&lt; / html&gt; 
   
 
 

网页浏览器说:

注意:未定义的索引:subbut在第17行的/Applications/MAMP/htdocs/decwargen.php中

当我第一次进入页面时,

注意:未定义的索引:/Applications/MAMP/htdocs/decwargen.php中的crtd 第24行

输入数据时。 有人可以帮忙吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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条)

相关推荐 更多相似问题