Nathan Nathan - 3 months ago 11
PHP Question

PHP Trying to get property of non-object in "C:\...."

I am trying to query to check if a password matches a username, When I try to create the class file with the validation I get "Trying to get property of non-object" when I use var_dump.

I have a db class that has all the functions to allow the functionality of querying database, They work fine as I can insert to the database.

class Login extends db{

public function loginValidation($username,$password){

$password; $username;

$query = "SELECT username FROM test WHERE password = '".$username."' AND username = '".$password."'";
$queryExists = $this->query($query);

if($queryExists->num_rows > 0){
return true;
} else{
return false;
}

}

}


Edit -----------

My SQL query seems to be failing but it makes no sense... The values on this database have been set using a registration form made in a PHP site.

Here are the tables -

SELECT * FROM users;
+----+----------+----------+
| id | username | pw |
+----+----------+----------+
| 19 | nathan | nathan |
| 20 | nathank | password |
| 21 | shanel | password |
| 22 | fsf | bdbdf |
| 23 | dawn | password |
| 24 | dsafsfd | sdfasf |
| 25 | kent | kent |
| 26 | kent` | kent |
+----+----------+----------+
8 rows in set


When I do the following query....

SELECT username FROM users WHERE pw = 'nathan';
Empty set


I receive nothing, It makes no sense because this is a simple SQL query that I am doing and it's failing?

Answer

so i think your code should be

class Login extends db{

    public function loginValidation($username,$password){

  //testing purpose
        $password="nathan"; $username="nathan";

        $query = "SELECT * FROM users WHERE pw = '".$password."' AND username = '".$username."'";
        $queryExists = $this->query($query);

        if($queryExists->num_rows > 0){
            return true;
        } else{
            return false;
        }

    }

}