You are not checking for error and I think you have one in the query line
public function getGenreName(){
$query = mysqli_query($this->con, "SELECT * FROM genres WHERE id='{$this->genre}'");
if ( ! $query ) {
echo $this->con->error;
return false;
}
$data = mysqli_fetch_array($query);
return $data['name'];
}
You could be a bit more efficient and just select name
as thats all you appear to be interested in.
public function getGenreName(){
$query = mysqli_query($this->con, "SELECT name FROM genres WHERE id='{$this->genre}'");
if ( ! $query ) {
echo $this->con->error;
return false;
}
$data = mysqli_fetch_array($query);
return $data['name'];
}
Althought this still contains the possibility of an SQL Injection Attack Even if you are escaping inputs, its not safe!
Use prepared parameterized statements in either the MYSQLI_
or PDO
API's
So you should really be be doing
public function getGenreName(){
$stmt = $this->con->prepare("SELECT name
FROM genres
WHERE id=?");
$stmt->bind_param('s', $this->genre );
$query = $stmt->execute();
if ( ! $query ) {
echo $this->con->error;
return false;
}
$result = $stmt->get_result();
$result->fetch_array(MYSQLI_NUM);
return $result[0];
}