Jump to content

$_GET returns empty always


vjgopinath

Recommended Posts

Hi All,

 

I am pretty new to PHP ( I am  a C Programmer).

 

I am trying a simple shopping cart website for my friend.

 

IN one of the pages, I am submitting some info, which is actually not showing up in my server side php.

Below is the HTML code to submit.

 

<a href="cart.php?action=add&p=5&size=small"> <img src="images/add_to_cart.gif"/> </a>

 

I tried to check the values of the parameters using

 

$action  = $_GET['action'] ;

 

Action stored empty. Then I checked the whole array

 

print_r($_GET) which returned 

 

Array( )

 

So, for some reason the value is always empty.

I tried the declaration GLOBAL $_GET, but no use.  :confused:

 

Any help/directions - much appreciated!

Link to comment
https://forums.phpfreaks.com/topic/211368-_get-returns-empty-always/
Share on other sites

Does the URL in the browser address bar display the expected URL with the ?action=add&p=5&size=small on it?

 

If it does, then your code is probably overwriting the $_GET variables.

 

If you want someone here to directly help with what your code might be doing, just post your code for the quickest solution.

 

The global keyword ONLY has meaning when used inside of a function definition (and even there it should not be used at all for well written code.) Using it on one of php's already superglobal variables, like $_GET, actually creates a new set of variables that DON'T have the values from the actual superglobal variable.

The HTML output that you posted works (produces the expected URL.) A few possibility exist that you would need to check out -

 

1) You are doing some URL rewriting and the GET parameters on the end of the URL are not being passed through,

2) The page that is the target of the URL is redirecting either back to itself or to another page and it is not passing the GET parameters on the end of the URL.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

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.