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


     $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>";

1 Year
Discussion Span
Last Post by 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.


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."

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.