Reputation: 21
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>
Upvotes: 2
Views: 117
Reputation: 27192
Try this it will work :
Use
"<p>".$comment_name." - ".$comment."</p>";
instead of
"<p>'$comment_name' - '$comment'</p>";
Upvotes: 0
Reputation:
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>";
Upvotes: 2