cabbie Posted April 4, 2013 Share Posted April 4, 2013 $count prints out 0 it is retrieving correct username and password from database. Ideas? <?php include_once ('connection.php'); class User{ private $db; public function __construct(){ $this->db = new Connection(); $this->db = $this->db->dbConnect(); } public function Login($username, $password) { if(!empty($username) && !empty($password)){ $st = $this->db->prepare("select * from users where username=? and password=?"); $st->bindParam(1, $username); $st->bindParam(2, $password); $st->execute(); $count = $st->rowCount(); Print $count; echo $username, ' ', $password; if($st->rowCount() == 1){ echo "User verified. Access granted"; }else{ echo "Incorrect username or password"; } }else{ echo "Please enter username and password"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/276540-rowcount/ Share on other sites More sharing options...
Psycho Posted April 4, 2013 Share Posted April 4, 2013 (edited) Per the manual: http://php.net/manual/en/pdostatement.rowcount.php PDOStatement::rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object. If the last SQL statement executed by the associated PDOStatement was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications. Edited April 4, 2013 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/276540-rowcount/#findComment-1422944 Share on other sites More sharing options...
Hall of Famer Posted April 4, 2013 Share Posted April 4, 2013 Well at least for MySQL database, PDOStatement::rowCount() seems to work just fine. I wonder what OP's database driver is though. Quote Link to comment https://forums.phpfreaks.com/topic/276540-rowcount/#findComment-1422967 Share on other sites More sharing options...
cabbie Posted April 5, 2013 Author Share Posted April 5, 2013 What is an alternative to check if a user exists during log in? Quote Link to comment https://forums.phpfreaks.com/topic/276540-rowcount/#findComment-1422990 Share on other sites More sharing options...
Jessica Posted April 5, 2013 Share Posted April 5, 2013 Check what user id was returned, or use the database engines COUNT function Quote Link to comment https://forums.phpfreaks.com/topic/276540-rowcount/#findComment-1422991 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.