我无法在php中使用$_GET/$_REQUEST
从网址获取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"。我尝试过在互联网上找到的所有其他方法。
答案 0 :(得分:1)
$get_posts = "SELECT * FROM posts (post_id) VALUES ('$get_id')";
将其更改为
$get_posts = "SELECT * FROM posts where post_id=$get_id";
如果您尝试获取该post_id的帖子内容
答案 1 :(得分:0)
SELECT查询应该写成
"SELECT * FROM posts WHERE post_id='$post_id'"