在PHP中的特定帖子上发表评论,postid在URL中给出

时间:2016-04-27 12:05:21

标签: php

我正在为学校做一个项目,它与Instagram有些相似。因此,您可以在时间轴上发布照片,然后其他用户就可以对此照片发表评论。

此评论选项已成功完成:您可以发表评论,评论会进入数据库。

评论classe:PHP代码

<?php

include_once "Db.class.php";

class Comment
{
    private $m_sComment;



    public function __set($p_sProperty, $p_vValue)
    {
        switch($p_sProperty)
        {
            case "Comment":
                $this->m_sComment = $p_vValue;
                break;
        }      
    }

    public function __get($p_sProperty)
    {
        $vResult = null;
        switch($p_sProperty)
        {
        case "Comment": 
            $vResult = $this->m_sComment;
            break;
        }
        return $vResult;
    }

        public function Save() {
            $conn = Db::getInstance();
            //$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $statement = $conn->prepare('INSERT INTO comment(comment, postID) VALUES(:comment, :postID)');
            $statement->bindValue(':comment', $this->Comment);
            $statement->bindValue(':userID', $this->Comment);
            $statement->execute();
        }

        public function GetRecentActivities($p_iPostID) {
            $conn = Db::getInstance();
            $allComments = $conn->query("SELECT * FROM comment WHERE postID = <post_id> ORDER BY id DESC;");
            return $allComments;
        }

    }

?>

但现在的问题是:在帖子的网址中,我发送了一个特定的POSTID。 http://localhost/oefening/post.php?p=9&u=8

p =&gt;帖子ID

u =&gt;用户ID

如何将tis postID发送到我的数据库?

1 个答案:

答案 0 :(得分:0)

你必须加强

的确切答案
<?php
    $url = "http://www.vnoel.com?cmd=list";  // The simple url
  $name = "option";                        // The parameter name
    $value = "new";                          // The parameter value
  $newUrl = $url . "?$name=$value";        // appending the values

  // prints:http://www.vnoel.com?cmd=list?option=new
    print($newUrl);
  ?>

在目的地页面中,您必须使用** $ _GET [&#39;选项&#39;] **