bigresource — 2008-06-09T14:18:29-04:00 — #1
I am getting the following error:
"PHP Notice: Use of undefined constant localhost - assumed 'localhost' in /var/www/file.php"
The line number I am getting is the first line of code below.
========= PHP CODE ================
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT URL FROM $type WHERE RAND='$rand' LIMIT 1";
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
What needs to be done. Thanks in advance for any help.
logic_earth — 2008-06-09T14:22:26-04:00 — #2
put quotes around localhost
bigresource — 2008-06-09T14:25:53-04:00 — #3
anthonysterling — 2008-06-09T14:30:50-04:00 — #4
Preferably single, but the time you had taken to reply would have been sufficient to try both... :rolleyes:
bigresource — 2008-06-09T14:33:26-04:00 — #5
My log is like of 80 Mb full of this errors, it takes more time to download, open and read it to check if the error still exists.
I really appreciate your help.
danltn — 2008-06-09T15:55:23-04:00 — #6
Just to explain what's happened so you know next time.
You've used the constant 'localhost' without any quotes, because you hadn't previously called defined('localhost) or define('localhost', 'localhost'); PHP looked in the constants table but couldn't find localhost.
This in turn throws a warning, but also takes PHP to interpret that constant: localhost, as it's actual string value. 'localhost'.
This is another reason you should ensure you always use quotes when calling indexes in arrays (unless of course you want to call the constant value.)
E.g. $array['key'] is about 4-6x faster than $array[key] and also wouldn't cause problems if you had define('key', 'blah'); before hand. If you had then you would actually look for the $array['blah'] key.
Hope this helps you understand,