As weekendrockstar correctly said, when a user logs in their $_SESSION variables are set up which are accessible from every subsequent page in your website. Therefore it isn't necessary to pass the id number as a querystring of the header statement in login.php.
So, instead of using header ("Location: myaccount.php?id='" .$_SESSION['user_id']."'"); you can simply go back to the original header ('Location: myaccount.php');
Then, in myaccount.php, use
$id = $_SESSION['user_id'];
in order to get the user's id number. You can then use that variable $id to display the individual page for that user (which you must already be doing).
I'm not sure why login.php is failing to redirect correctly sometimes unless it's a timing issue, but if that is the problem, then the above change should solve it.
Sorry for the confusion and hope this explains it better.