Notice: Undefined index $

This question already has an answer here:

  • PHP: “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” 25 answers
  • Reference - What does this error mean in PHP? 30 answers

  • 通过使用isset!empty

    <?php
        $name    = (isset($_POST['name'])    ? $_POST['name']    : '');
        $email   = (isset($_POST['email'])   ? $_POST['email']   : '');
        $message = (isset($_POST['message']) ? $_POST['message'] : '');
    ?>
    

    只需在代码中进行更改即可:

    if (isset ($_POST['name'])) {
      $name = $_POST['name'];
    }
    if (isset ($_POST['email'])) {
      $email = $_POST['email'];
    }
    if (isset ($_POST['message'])) {
      $message = $_POST['message'];
    }
    
    $from = 'From:';
    $to = '86376@ict-idcollege.nl';
    $subject = 'Hello';
    
    if (isset ($_POST['human'])) {
      $human = $_POST['human'];
    }
    

    place the code you have above inside a test block as follows

     if (isset($_POST['submit'])) {
       $name = $_POST['name'];
       $email = $_POST['email'];
      ...
      until the end of ?>
    

    this is because when ever the page loads without the form submission. (because you have the control logic and display logic in the same file) it executes the code on the top.

    链接地址: http://www.djcxy.com/p/69712.html

    上一篇: 在PHP中联系表单

    下一篇: 注意:未定义索引$