I am a starting PHP/sql-programmer, I am making a dashboard just for learning and I have a question. I want to let the page show something like this:
ID Name IP Rank
1 Willem 127.0.0.1 5
2 You 127.0.0.1 3
<table style="width:100%;color:white;">
<tr>
<th><center>ID</center></th><th>Naam:</th><th>IP:</th><th><center>Actie</center></th>
</tr> <?php
$d = $con->query("SELECT * FROM tbl_users ORDER BY id DESC LIMIT 1000");
while($r = $d->fetch_object()){
?>
<tr>
<td style="width:35px;text-align:center;"><?php echo $r->id; ?></td>
<td><?php echo $r->userName; ?></td>
<td><font color="red">Geblokkeerd</font></td>
<td style="width:50px;text-align:center"><a href="./ase_users?type=edit&id=<?php echo $r->id; ?>">Bewerk</a></td>
</tr>
<?php } ?>
</table
But if I put this code in de page, it gives me the following error:
Notice: Undefined variable: conn in /home/xxxxxxx/domains/xxxxxxx.nl/public_html/dashboard/beheer.php on line 133
Fatal error: Call to a member function query() on null in /home/xxxxxxxx/domains/xxxxxx.nl/public_html/dashboard/beheer.php on line 133
The dbconfig
dbconfig.php
<?php
class Database
{
private $host = "localhost";
private $db_name = "xxxxxx";
private $username = "xxxxxx";
private $password = "xxxxxx!";
public $conn;
public function dbConnection()
{
$this->conn = null;
try
{
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exception)
{
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>
Does anyone knows how to fix this?