Why try and make your own cookies and keep up with em from page to page when PHP already does that for ya.
http://www.php.net/manual/en/ref.session.php
This creates cookies and keeps up with the user for you. You could do it with your own cookies and session type stuff, but why code something twice.
What I would do from here is say:
if (MYSQL_NUM_ROWS($result) == 0) {
// the we couldnt find a password or username
else {
//start a session
session_start();
session_register("USER");
// Now we can use USER like a array
$USER["name"] = $username;
$USER["ID"] = mysql_result($result,0,"ID");
or whatever else you want.....
then on everypage (before!!!!!!!!!!!) ANY html or ANY output to the browser do a session_start(); followed by a session_register("USER"); . I only stress ANY cause there have been a lot of problems posted to the board about getting warnings on there pages cause they outputed before they registered there sessions.
Hope that Helps! (And is what you want 🙂 )