2

This is my code. I'm trying to print the comments on my site. The query and everything works since I tried it in an empty project but here it doesn't echo. The comments update in the database but they just don't show. What am I missing?

<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>
smottt
  • 3,272
  • 11
  • 37
  • 44
sam
  • 21
  • 2
  • 1
    MUST READ : http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – sodawillow Jan 07 '15 at 08:53
  • Plz note that mysql_query is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. –  Jan 07 '15 at 09:13

3 Answers3

2

Your variable name is in single quote, it must me concat or place in double quote..

For Ex

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

or

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

Try this it will work :

Use

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

instead of

"<p>'$comment_name' - '$comment'</p>"; 
Debug Diva
  • 26,058
  • 13
  • 70
  • 123
-1
echo "<p>".$comment_name."-".$comment."</p>"; 
Priyank
  • 3,778
  • 3
  • 29
  • 48