PHP エラー メッセージ「未定義の定数の使用」はどういう意味ですか? 質問する

PHP エラー メッセージ「未定義の定数の使用」はどういう意味ですか? 質問する

PHP はログに次のエラーを書き込みます: 「注意: 未定義の定数が使用されています」。

ログ内のエラー:

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]);

これはどういう意味ですか? また、なぜこれが表示されるのですか?

ベストアンサー1

departmentは、(ここでは配列キーとして使用されます)。PHP の文字列は引用符で囲む必要があります。昔は PHP は単語 1 個の文字列に引用符を使用することに寛容でしたが、今ではそのような時代は過ぎ去りました。

したがって、'department'または である必要があります"department"

他のエラーについても同様です。

department現状では、、、、などnameと呼ばれる定数を探していました。そのような定数が見つからない場合、PHP は (奇妙なことに) それを文字列 (「部門」など) として解釈しますが、そのことについて警告します。明らかに、後でそのような定数を定義すると、これは簡単に壊れる可能性があります (ただし、小文字の定数を使用するのは悪いスタイルです)。emailmessage

おすすめ記事