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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.