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:

JavaScript:
function callstats(stats) {
    var stats_id = stats.parentNode.firstElementChild;
    post_tag = stats_id.id.split('.')[0];
    post_id = stats_id.id.split('.')[1];
    //alert(post_tag);
    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.

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

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:
http://localhost:8080/reminderapp/callstats.php?tag=Once&id=235
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:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
var_dump($_GET);

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:

http://localhost:8080/reminderapp/callstats.php?var1=test&var2=test2

Report back with the output and we'll go from there
0
Adebayo OjoRegional Network ManagerAuthor Commented:
I got these:
From URL: http://localhost:8080/reminderapp/callstats.php?var1=test&var2=test2
C:\wamp64\www\reminderapp\callstats.php:4:
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
C:\wamp64\www\reminderapp\callstats.php:4:
array (size=2)
  'tag' => string 'Once' (length=4)
  'id' => string '235' (length=3)

Open in new window

0
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...
$_GET['tag']

Open in new window

it will probably work.
1
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

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 :)
1
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?
0
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.
1
Chris StanyonWebDevCommented:
Look at your URL:

http://localhost:8080/reminderapp/callstats.php?tag=Once&id=235

You have 2 variables in there - one called tag and one called id - that's it !
1
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
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.