Well that would be because you're setting the cookie expiry time to the exact second that they are created, you need to either set it to some time in the future, or to just leave out the data parameter to have it delete itself when the user closes their browser.
So option 1, just make the cookie last longer.
$time = mktime()+1000;
$date = date("l, d-M-y H:i:s", ($time+3600)); //Time + 3600 seconds (1hour)
setcookie("errorusername", $msg, $date);
Option 2, just loose the date altogether.
$time = mktime()+1000;
setcookie("errorusername", $msg);
That should work for you now 🙂