我的回声语句不会显示在 html 行中


My echo statement wont show in html lines

这是我的代码。我正在尝试在我的网站上打印评论。查询和一切正常,因为我在一个空项目中尝试过它,但在这里它没有回声。注释会在数据库中更新,但它们只是不显示。我错过了什么?

<h1>Leave a comment below!</h1>
<?php
$find_comments = mysql_query("SELECT * FROM comments");
if ($find_comments) {  
    while ($row = mysql_fetch_assoc($find_comments)) {
        $comment_name = $row['name'];
        $comment = $row['comment']; 
        echo "<p>'$comment_name' - '$comment'</p>"; 
    }
}
if(isset($_GET['error'])) {
    echo "<p>100 per limit";
}
?>
<form action="post_comments.php" method="post">
    <p>Your Name: </p>
    <input  type="text" name="name" size="40" maxlength="30" placeholder="Enter name..." </input><br><p>
    <p>Your Email: </p>
    <input  type="text" name="email" size="40" maxlength="30" placeholder="Enter email..." </input><br><p>
    <p>Your comment: </p>
    <textarea  type="text" name="comment" cols="50" rows="10" placeholder="Enter comment..."></textarea><br><p>      
    <input  type="submit" name="submit" value="Submit comment!" ></input>
</form>

你的变量名在单引号中,它必须连接或放在双引号中。

对于前

            echo "<p>$comment_name-$comment</p>"; 

            echo "<p>".$comment_name."-".$comment</p>";

试试这个它会起作用:

"<p>".$comment_name." - ".$comment."</p>"; 

而不是

"<p>'$comment_name' - '$comment'</p>"; 
echo "<p>".$comment_name."-".$comment."</p>";