I would like to get the usergroup from my database, and then check if it is 2 (which would mean its an Admin). I currently have this code as setup:
Login.php
<?php
//process login form if submitted
if(isset($_POST['submited'])){
$username = trim($_POST['username']);
$password = trim($_POST['password']);
if($user->login($username,$password)){
//logged in return to index page
$_SESSION['login'] = "$username";
header('Location: index.php');
exit;
} else {
$message = '<p class="error">Wrong username or password</p>';
}
}//end if submit
if(isset($message)) { echo $message; }
?>
<div class="lockscreen-credentials"> <form class="form-signin" role="form" method="post" action="">
<input type="text" class="form-control" name="username" placeholder="Username" required autofocus>
<div class="input-group">
<input type="password" class="form-control" placeholder="password" name="password" required/>
<div class="input-group-btn">
<button class="btn btn-flat" name="submited"><i class="fa fa-arrow-right text-muted"></i></button>
</div>
</div></form>
</div><!-- /.lockscreen credentials -->
And this is the class that is called (class.user.php):
public function login($username,$password){
$hashed = $this->get_user_hash($username);
*$st = $this->_db->prepare('SELECT userGroup FROM users WHERE username = :username');
$st->execute(array('userGroup' => 2));
$rows = $st->fetch();
if($st = 2) {
$_SESSION['loggedin'] = true;
return true;
}*
}
public function logout(){
session_destroy();
}
As you can see the code, within the stars (*), is where I am trying to check whether the field's value is 2. If so I want it to log in. If not, i want it to redirect. My error is:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in D:*****\classes\class.user.php:42 Stack trace: #0 D:******\classes\class.user.php(42): PDOStatement->execute(Array) #1 D:*******\login.php(43): User->login('demo', 'demo') #2 {main} thrown in D:*******\classes\class.user.php on line 42
Assign the correct value in WHERE clause