class - Getting value from database field and check if the same as variable in PHP? -


i usergroup database, , check if 2 (which mean admin). have code 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 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 class called (class.user.php):

public function login($username,$password){       $hashed = $this->get_user_hash($username);      *$st = $this->_db->prepare('select usergroup users username = :username');     $st->execute(array('usergroup' => 2));      $rows = $st->fetch();      if($st = 2) {         $_session['loggedin'] = true;         return true;     }*   }  public function logout(){     session_destroy(); } 

as can see code, within stars (*), trying check whether field's value 2. if want log in. if not, want redirect. error is:

fatal error: uncaught exception 'pdoexception' message 'sqlstate[hy093]: invalid parameter number: parameter 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 correct value in clause

  $st = $this->_db->prepare('select usergroup users username = :username');   $st->execute(array('username' => "some user name"));   $rows = $st->fetch();  if($rows['usergroup'] == 2) {     $_session['loggedin'] = true;     return true; } 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -