i copied the code and ran it through the php interpreter in syntax check mode. there is a parse error, here it is.
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in test.php on line 3
i didnt look over the rest but i think the 3rd line should be changed from
$query = "SELECT FROM poll WHERE pid='.$COOKIE['voted'].'";
to
$query = "SELECT FROM poll WHERE pid='" . $COOKIE['voted'] . "'";