0
我無法從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
返回 「失敗」。我嘗試了其他所有可以在互聯網上找到的方法。
你的問題不是你無法獲得post_id,而是你的選擇查詢無效。 **您應該檢查您的錯誤日誌中是否有錯誤消息。**此外,您可以[SQL注入](http://php.net/manual/en/security.database.sql-injection.php)和應該真正使用[Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)而不是連接你的查詢。特別是因爲你沒有逃避用戶輸入! –
謝謝Magnus。我試着改變我的SELECT查詢。它的工作現在。 – Himakar
請標記答案,然後至少投票 –