PHP returns 'NULL' for query string.

What could be the issue with my script? When I send some variables from JavaScript to PHP, I want PHP to pick the variables with $_GET from my URL query string, but PHP is returning "undefined variable" Below is my scripts:

function callstats(stats) {
    var stats_id = stats.parentNode.firstElementChild;
    post_tag ='.')[0];
    post_id ='.')[1];
    window.location = "http://localhost:8080/reminderapp/callstats.php?tag=" + post_tag + "&id=" + post_id;

Open in new window

NOTE: the alert(post_tag) in line 5 above returns the correct value.

if(isset($_GET['post_tag'])) {
    $tag = lcfirst(($_GET['post_tag']));
    $id = ($_GET['post_id']);

Open in new window

NOTE: My browser also showed correct URL with correct 'tag' and 'id', but var_dump on variable id and tag in PHP is still returning 'NULL'
Below is my browser URL after the javascript is fired:
The browser URL has correct tag and Id as supplied by the JavaScript, but PHP is not 'GETing' it.
Please help me, why is this?
Adebayo OjoRegional Network ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
OK. Time to do some quick debugging.

In your PHP script, add this to the very top of your page:

ini_set('display_errors', 1);

Open in new window

And then call your page manually by typing it's address into your browser, along with a test querystring, such as:


Report back with the output and we'll go from there
Adebayo OjoRegional Network ManagerAuthor Commented:
I got these:
From URL: http://localhost:8080/reminderapp/callstats.php?var1=test&var2=test2
array (size=2)
  'var1' => string 'test' (length=4)
  'var2' => string 'test2' (length=5)

Open in new window

And from URL: http://localhost:8080/reminderapp/callstats.php?tag=Once&id=235
array (size=2)
  'tag' => string 'Once' (length=4)
  'id' => string '235' (length=3)

Open in new window

Dave BaldwinFixer of ProblemsCommented:
The obvious problem is that your PHP code is looking for 'post_tag' and not 'tag'.  If you change it to...

Open in new window

it will probably work.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Dave BaldwinFixer of ProblemsCommented:
And $_GET['id'], not $_GET['post_id'].

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris StanyonWebDevCommented:
Ha! Yeah Dave - that'll be it :)
Adebayo OjoRegional Network ManagerAuthor Commented:
Thanks guy. This solve it! But why is it not taking 'post_tag' but accepting just ordinary 'tag'?
Any reason?
Dave BaldwinFixer of ProblemsCommented:
Yes.  The name of the variable in the GET query string is 'tag' and not 'post_tag'.  I don't know why you are adding 'post_' to the PHP code names.
Chris StanyonWebDevCommented:
Look at your URL:


You have 2 variables in there - one called tag and one called id - that's it !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.