Reputation: 41
I am trying to display and later amend the data inserted into this database on my web page. But the data is not displaying. I corrected my mistakes from my previous post and tried to troubleshoot. I believe the connection to the database is working because I am able to insert data into the database.
/*top of page invites.php*/
<?php
include("LoginRegistrationSystem/connect.php");
include("guestlist.php");
include("functions.php");
if(logged_in())
{
?>
/*in invites.php*/
<?php
$sql = "SELECT fname, lname, email, contact FROM guestlist";
$resultset = mysqli_query($con, $sql) or die("database error:".
mysqli_error($con));
echo "<table border="2">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Contact</th>
<th>Invitation</th>
</tr>";
while($row = mysqli_fetch_array($resultset))
{
echo "<tr>";
echo"<td>" . $row['fname'] . "</td>";
echo"<td>" . $row['lname']. "</td>";
echo"<td>" . $row['email']. "</td>";
echo"<td>" . $row['contact']. "</td>";
echo "<tr>";
}
echo "</table>";
mysqli_close($con);
?>
/*LoginRegistrationSystem/connect.php*/
<?php
$con = mysqli_connect("localhost","root","","registration");
if(mysqli_connect_errno())
{
echo "Error occured while connecting with database
".mysqli_connect_errno();
}
session_start();
?>
Upvotes: 0
Views: 181
Reputation: 460
There is one major error I'm spotting. Near the top of the code, you have a conditional:
if(logged_in()) {
but no closing brace to match it. If your page isn't loading at all, this is likely the problem.
If you fix this and the table still doesn't display, make sure that you have permissions to SELECT
on the guestlist
table. It would be odd, considering that you can INSERT
into the database, but check it nonetheless. Permissions errors been a huge cause of headache for me in the past.
As a bit of friendly advice, you might also want to consider switching from mysqli_fetch_array
to mysqli_fetch_assoc
. While this will not change how your program functions for the purposes here, with mysqli_fetch_array
the results are indexed both numerically and associatively, i.e. there is both a $row[0]
and a $row['fname']
even though they are the same thing. mysqli_fetch_assoc
returns only the associative array, i.e. there are no numerical indices in the return value.
Also, you should indent your code properly. It will drastically improve readability and help you with debugging.
Upvotes: 1
Reputation: 26
Try this: while($row = mysqli_fetch_assoc($resultset)){ .... }
Upvotes: 0