You have to answer this question before its comments can be revealed, this way we won’t spoil the answer for you.
PHP and MySQL
You can set a cookie (if the user is accepting them)
From within your PHP page, but only before it send out any data to the browser.
From within your PHP page; you can set a cookie at any time if your server is configured to buffer your output, but you can only send it before any regular (HTML) data is send to the browser if your server is configured to NOT buffer (see php.ini)