I agree with Chris and I want to add that there's no need to determine what type of integer the field is in your insert query, like you did:
$QUERY="INSERT INTO board_uid_pooltracking (type, first, last) VALUES ($TYPE, $FIRST::int8, $LAST::int8)";
I suggest you remove the ::int8 after the string you insert and as Chris said have all your values in single quotes.
$QUERY="INSERT INTO board_uid_pooltracking (type, first, last) VALUES ('$TYPE', '$FIRST', '$LAST')";
Oh saw it right now... At the end of your insert query string you have an additional semicolon: $LAST::int8);"; Remove the one that is before the double quotes...
At the end I want to tell you that it is better to have the $DBHANDLER string in a separate file, say config.inc so you won't have to type it down in every file you want to do a db query... Hope I helped 🙂