[英]Cant get id from url php using $_GET / $_REQUEST methods
I cant get the ID from url using $_GET/$_REQUEST
in php. 我无法在php中使用$_GET/$_REQUEST
从URL获取ID。
my link 我的链接
http://localhost/Social/single.php?post_id=1
my code 我的代码
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
It returns "FAILED". 它返回“ FAILED”。 I have tried every other method I could find on internet. 我尝试了在互联网上可以找到的所有其他方法。
actually you are getting the id but it gives you failed because you sql query is not correct 实际上,您正在获取ID,但由于您的SQL查询不正确,它给您失败
$get_posts = "SELECT * FROM posts (post_id) VALUES ('$get_id')";
change it to something like 将其更改为
$get_posts = "SELECT * FROM posts where post_id=$get_id";
if you are trying to fetch the post contents of that post_id 如果您尝试获取该post_id的帖子内容
SELECT查询应该写成
"SELECT * FROM posts WHERE post_id='$post_id'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.