当我使用循环中的表单字段发布评论时,博客的特定 ID 不会传递到 php 脚本。所以评论没有分配给它打算去的博客。
<?php
$conn = mysql_connect("localhost", "ooze", "");
mysql_select_db ("ooze");
$result = mysql_query ("select * from blog") or die(mysql_error());
$result2 = mysql_query ("select * from blog, blogcomment where blog.ID = blogcomment.blogID") or die(mysql_error());
$i = 1;
while($row = mysql_fetch_array($result))
{
echo "<h1>$row[title]</h1>";
echo "<p class ='second'>$row[blog_content]</p> ";
echo "<p class='meta'>Posted by .... • $row[date] • <a href='#' onclick=\"toggle_visibility('something$i'); return false\">Comments</a><div id='something$i' style='display: none;'>";
$i++;
while($row = mysql_fetch_array($result2))
{
echo "<p class='third' >$row[commentdate] • $row[username]</p><p>said:</p> <p>$row[comment]</p>";
}
if ( isset ($_SESSION["gatekeeper"])) {
echo '<form method="post" name="result_'.$row["ID"].'" action="postcomment.php"><input name="ID" type = "hidden" value = "'.$row["ID"].'" /><input name="comment" id="comment" type="text" style="margin-left:20px;"/><input type="submit" value="Add comment" /></form>';
}
else {
echo '<p class="third"><a href="register.html">Signup </a>to post a comment</p>';
}
echo "</div>";
}
mysql_close($conn);
?>