Ok, let's do this. First of all, a little tip: instead of checking if the form was submitted by verifying the $submit var, I personally prefer this:
if (count($POST) > 0) // If you use GET just change to $GET
{
echo "form submitted";
}
Note: Take a good look at PHP's predefined variables at http://www.php.net/manual/en/language.variables.predefined.php since you will use it a lot, and not only for sessions.
Ok, now to the real problem:
Once the user logs in, you register a $username var as a session var, so it's quite simple. In the next pages all you have to do is to check if this session var exists, like this:
session start(); // This must be ALWAYS the first line of code
if (isset($_SESSION['username']))
{
echo "User is logged in";
}
else
{
echo "Hey you're not logged in yet, man!";
}
Notice that if you already registered a session var (and you did, in this case) there is no need at all to check against the database.
Now a nice tip: If you want you can use this piece of code with $POST (for each form field) or $SESSION (for each session var) to use these vars like if they were previously setted in your code. Take a look:
foreach ($_SESSION as $key => $val)
{
$$key = $val; //this is a cool thing: a variable variable
}
So, if you have like dozens of session vars you can call them directly, e.g.:
Instead of $_SESSION['username']
you can use $username!
Take a good reading. I hope I don't get misunderstood, you're going in the right way, but you should really brush up with some PHP book or on-line reference, since you're doing some simple mistakes in your code.
Hope it helps you. Good luck!😉