Jump to content

$_GET not working

Recommended Posts


I am working on a cms site but I am having trouble with retrieving some info by id. I followed a tutorial on youtube and my code looks correct but my ID string is empty. Any help would be greatly appreciated.

Class with functions

class Article {
    public function fetch_all(){
        global $pdo;

        $query= $pdo->prepare("SELECT * FROM article");
        return $query->fetchAll();
    public function fetch_data($article_id)
        global $pdo;
        $query = $pdo->prepare("SELECT * FROM article WHERE article_id =?");
        $query->bindValue(1, $article_id);
        return $query->fetch();


Call to functions


$article = new Article;

var_dump($_GET, $_POST);

if (isset($_GET['id'])){
    $id = $_GET['id'];
    $data = $article->fetch_data($id);


When I var_dump the get and post I get array(0) { } array(0) { }. fetch all works great but fetch data does not and I am not sure where the post id is pulling from since there isn't a prior connection. 

Thank You,


Share this post

Link to post
Share on other sites
Posted (edited)

$_GET and $_POST are a function of your HTML form and/or URL. You didn't post any of that.

P.S. Please use the code (<>) icon and select the proper type for your PHP and/or HTML.

Edited by gw1500se

Share this post

Link to post
Share on other sites

The var dump results are because you don't have anything in those arrays.   Did you get to this script via a web page that contained a form of yours or a url that used any parms?  If you didn't, then you don't have any input to retrieve from $_GET or $_POST    Why did you expect anything there?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.