First PHP login system This is my first attempt at a login system! I've only had roughly 2 days of experience with MySQL and PHP so far and this is what I came up with:

&lt;?php
    session_start();

    //Start Database
        $IP = "";
        $user = "";
        $pass = "";
        $db = "";
        $con = mysqli_connect($IP, $user, $pass, $db);

        // Check connection
        if ( mysqli_connect_errno() ) {
            echo "&lt;div&gt;";
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
            echo "&lt;/div&gt;";
        }

    // Pretty much kicks out a user once they revisit this page and is logged in
    if( $_SESSION["name"] )
    {
        echo "You are already logged in, ".$_SESSION['name']."! &lt;br&gt; I'm Loggin you out M.R ..";
        unset( $_SESSION );
        session_destroy();
        exit("");
    }

    $loggedIn = false;
    $userName = $_POST["name"] or "";
    $userPass = $_POST["pass"] or "";

    if ($userName &amp;&amp; $userPass )
    {
        // User Entered fields
        $query = "SELECT name FROM Clients WHERE name = '$userName' AND password = '$userPass'";// AND password = $userPass";

        $result = mysqli_query( $con, $query);
        $row = mysqli_fetch_array($result);

        if(!$row){
            echo "&lt;div&gt;";
            echo "No existing user or wrong password.";
            echo "&lt;/div&gt;";
        }
        else
            $loggedIn = true;
    }

    if ( !$loggedIn )
    {
        echo "
            &lt;form action='logmein.php' method='post'&gt;
                Name: &lt;input type='text' name='name' value='$userName'&gt;&lt;br&gt;
                Password: &lt;input type='password' name='pass' value='$userPass'&gt;&lt;br&gt;
                &lt;input type='submit' value='log in'&gt;
            &lt;/form&gt;
        ";
    }
    else{
        echo "&lt;div&gt;";
        echo "You have been logged in as $userName!";
        echo "&lt;/div&gt;";
        $_SESSION["name"] = $userName;
    }

?&gt;
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

https://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 &amp;&amp; $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: 


http://www.phpeasystep.com/workshopview.php?id=6