What does the PHP error message “Notice: Use of undefined constant” mean?

前端 未结 9 2171
悲&欢浪女
悲&欢浪女 2020-11-21 05:04

PHP is writing this error in the logs: \"Notice: Use of undefined constant\".

Error in logs:

PHP Notice:  Use of undefined constant          


        
相关标签:
9条回答
  • 2020-11-21 05:45

    you probably forgot to use "".

    For exemple:

    $_array[text] = $_var;
    

    change to:

    $_array["text"] = $_var;
    
    0 讨论(0)
  • 2020-11-21 05:48

    You missed putting single quotes around your array keys:

    $_POST[email]

    should be:

    $_POST['email']

    0 讨论(0)
  • 2020-11-21 05:56

    Insert single quotes.

    Example

    $department = mysql_real_escape_string($_POST['department']);
    $name = mysql_real_escape_string($_POST['name']);
    $email = mysql_real_escape_string($_POST['email']);
    $message = mysql_real_escape_string($_POST['message']); 
    
    0 讨论(0)
  • 2020-11-21 06:01

    The correct way of using post variables is

    <?php
    
    $department = $_POST['department'];
    
    ?>
    

    Use single quotation(')

    0 讨论(0)
  • 2020-11-21 06:04

    You should quote your array keys:

    $department = mysql_real_escape_string($_POST['department']);
    $name = mysql_real_escape_string($_POST['name']);
    $email = mysql_real_escape_string($_POST['email']);
    $message = mysql_real_escape_string($_POST['message']);
    

    As is, it was looking for constants called department, name, email, message, etc. When it doesn't find such a constant, PHP (bizarrely) interprets it as a string ('department', etc). Obviously, this can easily break if you do defined such a constant later (though it's bad style to have lower-case constants).

    0 讨论(0)
  • 2020-11-21 06:04

    Looks like the predefined fetch constants went away with the MySQL extension, so we need to add them before the first function...

    //predifined fetch constants

    define('MYSQL_BOTH',MYSQLI_BOTH);
    define('MYSQL_NUM',MYSQLI_NUM);
    define('MYSQL_ASSOC',MYSQLI_ASSOC);
    

    I tested and succeeded.

    0 讨论(0)
提交回复
热议问题