Chris Cox Chris Cox - 6 months ago 11
PHP Question

Use of undefined constant (TEXT)

ok, so I've run a query where one of the rows has a text value rather than numeric. So when I try to run the

if($i['row'] = text)
{
echo "info here";
}
else
{
echo "other info here";
}


it returns Use of undefined constant.

So how would I write the if statement?

Answer

text is a string here. It should be in quotes. Also if you are comparing the = should be == (for strict comparison use ===).

if($i['row'] == 'text')

Or

if(gettype($i['row'] == 'string') 

Constants are used without quotes.

define("SAMPLE_CONSTANT", 'sample value');
echo SAMPLE_CONSTANT; // prints sample value

So text is treated as constant in this context. And thus the error of Undefined Constant...

Comments