Assuming that the cookie was sent to the browser, it is not directly available within the same code that sets it until the page is refreshed or you browse to a different page and the headers are exchanged which is when the browser sends the cookie back to the web server and the $_COOKIE... variable becomes set.
Try putting this after your first opening php tag to see if there is a header problem -