Undefined constant is an error of level E_NOTICE, this can be set either by the error_reporting function or directive. It's a undefined constant because PHP first looks for a constant named foo, if it isn't found it'll throw the E_NOTICE error and then look for an array key named 'foo'. Example:
print $array[foo]; // undefined constant (most likely)
print $array['foo']; // do this instead
print "this is okay $array[foo] though"; // because constants aren't looked for in strings
define('a','b'); // define a constant a with the value b
$arr = array('a' => 'apple', 'b' => 'banana');
print $arr[a]; // banana
print $arr['a']; // apple
Not a valid resource is a little tougher to spot but with a little debugging it can be solved. The function mysql_error() can be very useful for this. An example:
if (!$result = @mysql_query($sql)) {
print "Invalid result, could not run query ($sql) : " . mysql_error();
exit;
}
The basic idea is that mysql_query() returns boolean false on failure and mysql_error() will tell you the problem. Maybe there isn't a database connection, or no selected database? If so, that might explain the undefined offset too.