1

小さな問題があります。このコードを使用すると:

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

Web ブラウザには次のように表示されます。

Notice: 未定義のインデックス: subbut /Applications/MAMP/htdocs/decwargen.php の 17 行目

最初にそのページにアクセスしたとき、

Notice: 未定義のインデックス: /Applications/MAMP/htdocs/decwargen.php の 24 行目の crtd

データを入力するとき。誰でも助けてもらえますか?

4

4 に答える 4

3

あなたの

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

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

最近の質問の編集から、次の変更も行います。

あなたの

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

if(isset($_POST ['subbut']))
        {
于 2013-10-26T14:47:02.233 に答える
0

最初にページに移動したとき $_POST['subbut'] は存在しません。フォームが投稿された後にのみ存在します。これを回避するには、isset を使用する必要があります。たとえば、代わりに次のコードを使用します

if(isset($_POST ['subbut'])){
        $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);

この行も変更します

Created on: <input type='text name='crtd' placeholder='10/10/13'><br>

これに

Created on: <input type='text' name='crtd' placeholder='10/10/13'><br>
于 2013-10-26T14:48:47.917 に答える