So basically my code isnt working here. The confusing part is that at a bare minimum it should be printing the table header, which it is not doing.
here is my function
public function getUsers(){
global $connectstr_dbhost, $connectstr_dbname, $connectstr_dbpassword, $connectstr_dbusername;
$link=mysqli_connect($connectstr_dbhost, $connectstr_dbusername, $connectstr_dbpassword,$connectstr_dbname);
$sql = "SELECT * FROM `users`";
$result = mysqli_query($link, $sql);
echo ("
<table border='1'>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Email</th>
</tr>
");
while($row = mysqli_fetch_array($result))
{
echo(
"<tr>" .
"<td>" . $row['id']. "</td>".
"<td>" . $row['fname'] . "</td>".
"<td>" . $row['lname'] . "</td>".
"<td>" . $row['username'] . "</td>".
"<td>" . $row['email'] . "</td>".
"</tr>"
);
}
echo "</table>";
}
Pretty new to php and I feel as if the answer is really simple, any assistance would be appreciated.
Maybe is that `user` over user. Try and see if resolve. If not try this code:
[TRY Save the content of the function in another file and just make an echo to see if the function is called]
public function getUsers(){
global $connectstr_dbhost, $connectstr_dbname, $connectstr_dbpassword, $connectstr_dbusername;
$link = mysqli_connect($connectstr_dbhost, $connectstr_dbusername, $connectstr_dbpassword,$connectstr_dbname) or die('Não foi possível conectar');
$sql = "SELECT * FROM users";
$result = $link->query($sql);
echo "
<table border='1'>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Email</th>
</tr>
";
while($row = $result->fetch_assoc()) {
echo "<tr>" .
"<td>" . $row['id']. "</td>".
"<td>" . $row['fname'] . "</td>".
"<td>" . $row['lname'] . "</td>".
"<td>" . $row['username'] . "</td>".
"<td>" . $row['email'] . "</td>".
"</tr>";
}
echo "</table>";
}
Figured it out, the problem was I had not imported the database class.