At a quick look:
Your code is vulnerable to SQL Injection: assume the user wants to hurt you, so always parse superglobals
$_GET
and$_POST
http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-phphttps://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php
To check if variable have values:
// good practice if (isset($userName, $userPass)) // bad practice if ($userName && $userPass )
More important:
Don't reinvent the wheel unless you plan on learning more about wheels.
A simple search on google for PHP login system
will give you a limitless number of examples from where you can learn how to build a proper system: