Wednesday, January 21, 2015

[PHP][Resolved] PHP error: Use of undefined constant

At usual, careless mistake would cause this error, for example, missed the dollar sign in front of your php value. Syntax highlighted in yellow is the right syntax which need to be aware in the example provided below:

Case 1:
if(title == ""){} //Wrong
if($title == ""){} //Right

Case 2:
$department = mysql_real_escape_string($_POST[department]); //Wrong
$department = mysql_real_escape_string($_POST['department']); //Right
Case 3:

$field_name = ‘department’;
$department = mysql_real_escape_string($_POST[$field_name]); //Right

Reference:
http://php.net/manual/en/language.constants.php
http://stackoverflow.com/questions/2941169/what-does-the-php-error-message-notice-use-of-undefined-constant-mean

No comments :

Post a Comment