I've been searching for the answer for a while, but no luck: I have defined a variable inside this function and I try to use it in the same function, but PHP gives me this:
Notice:
Undefined variable: query in C:\xampp\htdocs\liquidity\includes\layout\DBBroker.php on line 42 Warning: mysqli_query():
Empty query in C:\xampp\htdocs\liquidity\includes\layout\DBBroker.php on line 42
How is this possible? I define it and use it inside the same function. The function is prikaziClanove, the one with "//here the problem starts" next to it. Code:
<?php
define ("DBHOST", "localhost");
define("DBUSER", "standard_user");
define("DBPASS", "standard");
define("DBNAME", "liquidity");
class DBBroker {
private $dbhost;
private $dbuser;
private $dbpass;
private $dbname;
private $conn;
function __construct() { //connects to DB and checks the connection
$this->dbhost = DBHOST;
$this->dbuser = DBUSER;
$this->dbpass = DBPASS;
$this->dbname = DBNAME;
$this->conn = mysqli_connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
if (!$this->conn) {
die("Došlo je do greške pri konektovanju na bazu: ".mysqli_error($this->conn));
}
}
/*$conn = mysqli_connect(DBHOST, DBUSER, DBPASS, DBNAME);
if ($conn) {
die("Došlo je do greške pri konektovanju na bazu: ".mysqli_error($conn));
}*/
function chckResult($rs) { //checks the query result of query, $rs=result
if (!$rs) {
echo("Upit nije uspešno izvršen.");
}
}
function closeConnection() { //closes the connection
mysqli_close($connection);
}
function prikaziClanove($username) { //here the problem starts
$query = "SELECT * FROM clan WHERE username='".$username."';".
$result = mysqli_query($this->conn, $query);
$this->chckResult($result);
echo($result);
}
}
?>