Odd. I use the following code with success...
//get IP
$agent = $GLOBALS['HTTP_USER_AGENT'];
$ip = $GLOBALS['REMOTE_ADDR'];
// insert into logs table
$sql = "INSERT INTO logs VALUES ( NULL, '$ip', 'Failed', '$agent')";
Maybe post some code so I can see where yours breaks down at?