Here's my error:
Fatal error: Call to undefined method validate::get_row_count() in /.../classes/database.php on line 42
my database class has this method:
public function get_row_count() {
return mysqli_num_rows($this->result);
}
and this that is causing the error
public function check_record_exists($sql) {
if ($this->result = mysqli_query($this->dbc, $sql)) {
if ($this->get_row_count() == 0) { //line 42
return FALSE;
} else {
return TRUE;
}
} else {
die (mysqli_error($this->dbc) . '<br /><br />' . $sql);
return FALSE; //won't actually get here
}
} //function
I also have a validate class, that this constructor:
public function __construct() {
database::connect();
}
and this method that is calling the problem method in the database class
public function username_exists($to_check) {
if(database::check_record_exists("SELECT * FROM user WHERE username = '{$to_check}'")) {
$this->errors[] = 'Username <strong>' . $to_check . '</strong> is already taken, please try a different one';
return TRUE;
} else {
return FALSE; //returns TRUE if there is no error
}
}
First off, the method definitely exists in the database class, but the error is indicating that it's looking for the method in the validate class, but it says the error is in the database.php file
All the references to methods within the same class are $this->
I just don't understand how the classes/objects can be getting mixed up, and I've done a few other similar things that all work as intended.
It will work if I change $this->get_row_count() to database::get_row_count() within the database class, but I don't think I should have to do it, and I suspect it won't fix the underlying problem.
Thanks in advance