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


Place a comment on a specific post in PHP, the postid is given in the URL

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

此注释选项已成功完成:您可以放置注释,注释就会进入数据库。

注释类: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;
        }
    }
?>

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

p => 后置号

u => 用户标识

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

你必须增强它不准确的答案

<?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['选项']** 接收