【问题标题】:comment box using PHP and HTML is returning only last comment information for report form使用 PHP 和 HTML 的评论框仅返回报告表单的最后评论信息
【发布时间】:2017-10-26 02:24:53
【问题描述】:

我为我的网站创建了一个用户评论部分,并且 cmets 与举报滥用行为的标志一起显示在网页上。它在数据库comment_id、用户名、电子邮件、评论和用户评论的post_id中有五列。以下是我用来显示数据库中的 cmets 的 php 代码:

try
 {
  $result = $conn->prepare("SELECT * FROM user_comment WHERE post_id ='$post_id'");
 $result->execute();
 $count=$result->rowCount();

 $def_com = $count;
 if(!$count)
    {
      $def_com = "Be the First one to comment.";
    }
else{
    $data = array();
    while ($data = $result->fetch())
    {
        $datas[] = $data;
    }
    foreach ($datas as $data)
    {
    echo " <div class='col-md-12 com-row' >
    <img src='img/user.png' style='height:60px;width:60px;align:left'>"
    ." <p style='margin-left:80px; margin-top:-50px'> b>".$data['user_name']."</b>&nbsp;". 
                             $data['time']."&nbsp;&nbsp;".$data['comment_id']."<br>".$data['comment']. "</p>
    <a class='flagBtn smGlobalBtn flagdiv' name='report-comment' href='reportabuse.php'></a><br><br>";
} 

在给定帖子上显示所有 cmets 工作正常。我在会话变量中获得了帖子 ID,并在 select 语句中使用它。

我的问题是当我单击标记按钮时,我希望将评论 ID 传递到 reportabuse.php 页面。此 id 应与用户单击标志按钮的评论相对应。

如何获得它我已经尝试过会话变量,但它传递最后一条评论的 id 与用户点击哪个评论标志无关。

无论我尝试从帖子页面传递什么评论信息到报告滥用页面,它只显示最后一条评论的信息,这与点击哪个评论的标志按钮无关。我只需要单击其标志按钮的评论的信息。

我也尝试使用表单来显示 cmets,但没有用,问题仍然存在。

【问题讨论】:

  • 可以像这样在url中传递id吗 href='reportabuse.php?cmets_id=2
  • 感谢响应。它起作用了....

标签: php html mysql comments


【解决方案1】:

为什么不在a href 的URL 中将id 作为参数传递,例如href='reportabuse.php?cid=1234' 在 reportabuse.php 页面上询问 $_GET["cid"] 以获取在 url 中传递的 id。

更多关于 $_GET http://php.net/manual/en/reserved.variables.get.php

【讨论】:

  • 当我提交滥用报告表单时,它给出了一个错误:PHP 注意:未定义索引:第 5 行“文件路径”中的 cid 如何删除它。
  • 我试过 if(isset($_GET['cid'])){ $comment_id = $_GET['cid'];} 以及 if(isset($_POST['cid'] )){ $comment_id = $_GET['cid'];} 但它根本没有返回任何东西。
  • 您是否正在使用 URL 中的参数或表单的一部分向页面发布帖子?
  • 第二个选项也有错误 - 您正在检查 $_POST 变量,然后如果它有效,您正在调用 $_GET 变量。如果通过验证肯定会出问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-15
  • 1970-01-01
  • 2019-08-07
  • 1970-01-01
  • 1970-01-01
  • 2013-08-13
  • 1970-01-01
相关资源
最近更新 更多