I'm fairly new to php and I'm having problems understanding how to grab content from the DB using qa functions.
I'm trying to display a random user on the homepage and have sucsessfully connected and displayed content from the database using the following code in the qa-theme.php
Can you tell me of any protential problems connecting to the DB in this way, security e.t.c
Thanks in advance
function main(){
if($this->request=='')
{
$con = mysqli_connect("localhost","user","password","database");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM qa_users");
echo "<table border='1'>
<tr>
<th>User ID</th>
<th>Handle</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['userid'] . "</td>";
echo "<td>" . $row['handle'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
qa_html_theme_base::main();
}
else {
qa_html_theme_base::main();
}
}