Solution PHP Notice: Use of undefined constant x — assumed ‘x’

I once noticed the following notification when writing a PHP script:

PHP Notice:  Use of undefined constant uid - assumed 'uid' in /scripts/file.php on line 31
PHP Notice:  Use of undefined constant value - assumed 'value' in /scripts/file.php on line 32


The code was:

while($Row = mysqli_fetch_array($Result))
{
$uid = $Row[uid];
$phone =$Row[value];
…

To remove the notification, I quotes all values:

$uid = $Row['uid'];
$phone =$Row['value'];
...

Also, this notification may appear when we created a variable and indicated it after “echo” without the “$” symbol, for example:

$test = "123";
echo test;

And you need:

echo $test;
Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a comment

Leave a Reply