繁体   English   中英

无法使用$ _GET / $ _REQUEST方法从URL PHP获取ID

[英]Cant get id from url php using $_GET / $_REQUEST methods

我无法在php中使用$_GET/$_REQUEST从URL获取ID。

我的链接

http://localhost/Social/single.php?post_id=1

我的代码

function single_post() {

    if (isset($_REQUEST['post_id'])) {

        global $con;

        $get_id = $_REQUEST['post_id'];
        $get_posts = "SELECT * FROM posts (post_id) VALUES ('$get_id')";
        $run_posts = mysqli_query($con,$get_posts);

        if($run_posts) {
            echo "SUCCESS.";
        } else {
            echo "FAILED.";
        }
    }

}//singlepost ends here

它返回“ FAILED”。 我尝试了在互联网上可以找到的所有其他方法。

实际上,您正在获取ID,但由于您的SQL查询不正确,它给您失败

    $get_posts = "SELECT * FROM posts (post_id) VALUES ('$get_id')";

将其更改为

    $get_posts = "SELECT * FROM posts where post_id=$get_id";

如果您尝试获取该post_id的帖子内容

SELECT查询应该写成

"SELECT * FROM posts WHERE post_id='$post_id'"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM