If you can see that some of the users have a null in the db for the id it seems that this might be the problem. How do you have this column setup? It should be an auto incrementing primary key of the table with the not null attribute.
If the table is setup like this then there should never be a situation where the user can login but have no user id in the session. Make these updates to your db then try updating the records for the users that have a null value now. Once you update those users do some testing to see if the problem occurs again. Let us know if you have any questions or problems.