注意:我得到未定义的索引:在第13行提交

时间:2017-02-27 09:26:31

标签: php

        <?php
        include('connect.php'); 
        ?>
        <!DOCTYPE html>
        <html>
        <head>
        <meta charset="utf-8">
        <title>Exa</title>
         </head>
        <body>
        <pre>
        <?php
        if($_POST["submit"] == 1) 
        {
            if($_POST['label'] == '')
            {
                echo '<p>You must enter a label!</p>';
                $error= true;

            }   
            if($_POST['url'] == '')
            {
                echo '<p>You must enter a URL!</p>';
                $error= true;

            }   
            if($error != true) {
                $query = "INSERT INTO nav(label,url,target, position,status) VALUES('$_POST[label],'$_POST[url]','$_POST[target]','$_POST[position]',$_POST[status])";
           $result =mysqli_query($dbc, $query);
           if($result) {
           echo 'you added a new navigation link!';
          } else {
          echo 'An error has occurred'; 
          echo  mysqli_error($dbc);
           echo '<p>'.$query.'</p>';
        }
        }
        }
        ?>
        </pre>
        <h1>Navigation</h1>
        <form action="example.php" method="post">
        <p>* required field</p>
        <p>
        <label>Label: </label>
        <input type="text" name="label" size="50" placeholder="Enter A Label" value="">
        </p>

        <p>
        <label>Url: </label>
        <input type="text" name="url" size="50" placeholder="Enter A URL" value="">
        </p>
        <p>
        <label>Target: </label>
        <input type="text" name="target" size="50" placeholder="Enter A Target" value="">
        </p>
        <p>
        <label>Position: </label>
        <input type="text" name="position" size="50"  value="">
        </p>
        <p>
        <label>Status: </label>
        <input type="text" name="status" size="10"  value="">
        </p>
        <p><button type="submit" name= "submit" values="1">Add Navigation Link</button></p>

        </form>
        </body>
        </html>

    Notice:  Undefined index: submit in C:\xampp\htdocs\hello\example.php on line 13
what it is showing undefined submit in the code as the error?

是PHP表单验证类型的代码吗? 我正在代码中进行php表单验证 它在代码中显示未定义的提交是什么错误? 它是PHP表单验证类型的代码? 我正在代码中进行php表单验证

1 个答案:

答案 0 :(得分:0)

提交元素是: <button type='submit' name='submit' ...

而不是:

<input type='submit' name='submit' ...

更改它以传递该元素的值。