Guys, i am getting an unexpected T_While Error on my code, I cannot figure it out. can you help?

<?php

     $sql = "SELECT id, u_name, u_email, subj, phone FROM tb_cform ";

    $result = $conn->query($sql);

    echo '<table><tr><th>Name</th><th>Email</th><th>Subjec</th><th>Phone</th></tr>';
    if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
            echo "<tr><td>".$row["u_name"]."</td><td>".$row["u_email"]."</td><td>".$row["subj"]."</td><td>".$row["phone"]."</td></tr>";
        }
    } else {
        echo "0 results";
    }
    echo "</table>";
    $bd->close();

    ?> 

Hi,

can you provide the error message?

Member Avatar for diafol

This often occurs as a direct result of problems with preceding lines.

I was researching that t-while error and it does appear to happen when the statement is incorrect in some way.
Now it doesn't pop out at me why the while statement is failing so it's back to you to debug the failing line.
https://www.google.com/search?q=debug+php finds how to debug. Now in your system you set a breakpoint then examine the contents of the while tests and see where it went off the rails.

Member Avatar for diafol

Ther's nothing obvious from the snippet, but watch out for unbalanced braces or unterminated lines - but watch out for them upstream as it could be simply telling you - "Wow! Wasn't expecting a while statement there."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.