What does the PHP error message quot;Notice: Use of undefined constantquot; mean?(PHP 错误信息“注意:使用未定义的常量是什么意思?意思是?)
问题描述
PHP 正在日志中写入此错误:注意:使用未定义的常量".
PHP is writing this error in the logs: "Notice: Use of undefined constant".
日志错误:
PHP Notice: Use of undefined constant department - assumed 'department' (line 5)
PHP Notice: Use of undefined constant name - assumed 'name' (line 6)
PHP Notice: Use of undefined constant email - assumed 'email' (line 7)
PHP Notice: Use of undefined constant message - assumed 'message' (line 8)
相关代码行:
$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]);
这是什么意思,为什么我会看到它?
What does it mean and why am I seeing it?
推荐答案
你应该引用你的数组键:
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']);
按原样,它正在寻找名为 department、name、email、message 等的常量.当它没有找到这样的常量时,PHP(奇怪地)将其解释为字符串('department' 等).显然,如果您稍后确实定义了这样一个常量,这很容易破坏(尽管使用小写常量是不好的风格).
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).
这篇关于PHP 错误信息“注意:使用未定义的常量"是什么意思?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 错误信息“注意:使用未定义的常量"是什么意思?意思是?
基础教程推荐
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的PDF导出 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
