0

I'm getting an error on the <?php endwhile; ?> line.

Error:

Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE);

Code:

$result = mysqli_query($connect,"SELECT* FROM contacts");
    ?>

    <table width="800" cellpadding="10" cellspacing="5" border="2">
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Contact No</th>
            <th>Email</th>
        </tr>
    <?php while ($row = mysqli_fetch_array($result)); ?>
        <tr>
            <td><?php echo $row['first_name']; ?></td>
            <td><?php echo $row['last_name']; ?></td>
            <td><?php echo $row['contact_no']; ?></td>
            <td><?php echo $row['email']; ?></td>
        </tr>
    <?php endwhile; ?>
    </table>

No record is showing in the table. The page is just showing the error.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Zain
  • 15
  • 3

1 Answers1

2

If you want to use endwhile;, you should follow the while's condition with a colon (:), not a semicolon (;):

<?php while ($row = mysqli_fetch_array($result)): ?>
<!-- Here --------------------------------------^ >
Mureinik
  • 297,002
  • 52
  • 306
  • 350