verheesj Posted November 26, 2008 Share Posted November 26, 2008 Hey, I ran into a little issue, for some reason its not returning anything when Resource #5 is returned from the SQL by echo'ing out $this->query. Here is my code, it should return a message if the username is found but the password isn't, and if the username isn't found then it should do the same as u can see below. It just keeps redirecting to home.php when it should check <?php class system { private $mysql; private $username; private $password; private $query; private $main_url = 'http://example.com/'; function __construct() { require_once("assets/classes/mysql.class.php"); $this->mysql =& new mysql('localhost', '***', '***', '***'); } public function login($username, $password) { $this->username = $this->mysql->prepare($username); $this->password = $this->mysql->prepare(md5($password)); $this->query = $this->mysql->query("SELECT username FROM users WHERE username = '$this->username'"); if(!$this->query) { echo "We did not find any users with the username you entered. Please try again."; } else { $this->query = $this->mysql->query("SELECT username, password FROM users WHERE username = '$this->username' AND password = '$this->password'"); if(!$this->query) { return "We found the username, $this->username but the password you provided is wrong."; } else { $this->username = $_SESSION['username']; $this->password = $_SESSION['password']; return header("Location:" . $this->main_url . "home.php"); } } } } $system =& new system; ?> Link to comment https://forums.phpfreaks.com/topic/134352-solved-oop-system-issue/ Share on other sites More sharing options...
trq Posted November 26, 2008 Share Posted November 26, 2008 Just becasue a query succeeds does not meen it found results. You need to check if it actually found some data matching your query. Link to comment https://forums.phpfreaks.com/topic/134352-solved-oop-system-issue/#findComment-699503 Share on other sites More sharing options...
verheesj Posted November 26, 2008 Author Share Posted November 26, 2008 Yeah, I tried num_rows() in there and it still doesn't return anything, my num_rows() function is in the mysql class public function num_rows($result) { return @mysql_num_rows($result); } Link to comment https://forums.phpfreaks.com/topic/134352-solved-oop-system-issue/#findComment-699598 Share on other sites More sharing options...
trq Posted November 26, 2008 Share Posted November 26, 2008 Yeah, I tried num_rows() in there and it still doesn't return anything Can we see that code then? Link to comment https://forums.phpfreaks.com/topic/134352-solved-oop-system-issue/#findComment-699601 Share on other sites More sharing options...
verheesj Posted November 26, 2008 Author Share Posted November 26, 2008 <?php class system { private $mysql; private $username; private $password; private $query; private $main_url = 'http://example.com/'; function __construct() { require_once("assets/classes/mysql.class.php"); $this->mysql =& new mysql('localhost', '***', '***', '***'); } public function login($username, $password) { $this->username = $this->mysql->prepare($username); $this->password = $this->mysql->prepare(md5($password)); $this->query = $this->mysql->query("SELECT username FROM users WHERE username = '$this->username'"); if($this->mysql->num_rows($this->query ) < 1) { return "We did not find any users with the username you entered. Please try again."; } else { $query = $this->mysql->query("SELECT username, password FROM users WHERE username = '$this->username' AND password = '$this->password'"); if($this->mysql->num_rows($this->query ) > 1) { return "We found the username, $this->username but the password you provided is wrong."; } else { $this->username = $_SESSION['username']; $this->password = $_SESSION['password']; return header("Location:" . $this->main_url . "home.php"); } } } } $system =& new system; ?> Link to comment https://forums.phpfreaks.com/topic/134352-solved-oop-system-issue/#findComment-699615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.