Basic PHP class issue
<p>Going to start again!</p>

<p>I have a form that I use to login.</p>

<pre><code>&lt;form method="post" action="user.php"&gt;

&lt;label&gt;Username:&lt;/label&gt;&lt;label class="error"&gt;&lt;?php echo $form-&gt;error("username"); ?&gt;&lt;/label&gt;
&lt;input type="text" name="username" maxlength="25" class="text" value="&lt;?php echo $form-&gt;value("username"); ?&gt;"/&gt;

&lt;label&gt;Password:&lt;/label&gt;&lt;label class="error"&gt;&lt;?php echo $form-&gt;error("password"); ?&gt;&lt;/label&gt;
&lt;input type="password" name="password" value="&lt;?php echo $form-&gt;value("password"); ?&gt;" class="text" /&gt;

&lt;input type="submit" name="login" class="button" value="Login" /&gt;
</code></pre>

<p></p>

<p>This is my user.php file</p>

<pre><code>class User {

public function __construct() {

    $this-&gt;db = new Database(DB_TYPE, DB_HOST, DB_NAME, DB_USER, DB_PASS);

}

public function login() {

    //check username for errors
    $user = $_POST['username'];

    $field = "username";

    //check username isn't empty
    if (empty($user)) {
        $form-&gt;setError($field, "* Username not entered");
    }
    //username taken
    else {
        $query = $this-&gt;db-&gt;select("SELECT userid FROM user WHERE username = :username", array('username' =&gt; $user));
        if (!$query) {
            $form-&gt;setError($field, "*Username not found");
        }
    }

    //check passwords for error
    $pass = $_POST['pass'];

    $field = "pass";

    //check password isn't empty
    if (empty($pass)) {
        $form-&gt;setError($field, "*Password not entered");
    }
    //incorrect password
    else {
        $query = $this-&gt;db-&gt;select("SELECT userid FROM user WHERE username = :username AND password = :password", array('user' =&gt; $user, 'password' =&gt; Hash::create('sha256', $pass, HASH_PASSWORD_KEY)));
        if (!$query) {
            $form-&gt;setError($field, "*Password not found");
        }
    }

    //if errors exist, return to user - otherwise insert into db
    if ($form-&gt;num_errors &gt; 0) {
        return 1;  //Errors with form
    } 
    else{

        //use the userid and set it as session variable
        $query = $this-&gt;db-&gt;select("SELECT userid FROM user WHERE username = :username AND password = :password", array('user' =&gt; $user, 'password' =&gt; Hash::create('sha256', $pass, HASH_PASSWORD_KEY)));
        $_SESSION['userid'] = $query[0]['userid'];

        $_SESSION['logged_in'] = true;

        header("Location ".URL."dashboard.php");
    }
}
}
</code></pre>

<p>As you can see, I use <code>$form</code> which is in form.php.</p>

<p>What's the best way to access this class from the form itself?</p>

<p>Thanks.</p>
