Originally posted by Sharif
Never thought about the idea of $username being evil BUT is the code good? You know... the one I posted
The code is well structured; good job. I think the design flow needs a bit of work though. There's probably a couple of unnecessary comments in there (but that's a matter of opinion), and I can see two places where you declare an unnecessary variable ($status).
A good rule of thumb is this: don't declare a temporary variable if you're only going to use it once.
There are a few exceptions to this, but in your case here, you don't really "need" the extra $status variable.
Another potential problem is your mysql_num_rows() condition. By saying "greater than zero", and not checking your input, you open yourself up to a huge security hole. You might consider changing that to:
if(mysql_num_rows($result)==1)
{
// etc...
To ensure that you only ever get one valid user returned.
You can also scrub your input so that's it's safe for your query by using [man]mysql_real_escape_string/man.
Another thing I noticed:
In your first if() statement, you're assuming that $_SESSION['userid'] exists. That will throw a notice error if it doesn't exist. Just wrap it in an isset() or an empty().