Chris Cox Chris Cox - 1 year ago 45
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";
echo "other info here";

it returns Use of undefined constant.

So how would I write the if statement?


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')


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...