Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

using $_GET['varname'] vs $http_post_vars


lucilue2003

Recommended Posts

Posted

whats the difference between $http_post_vars

and the $_GET['varname'] method. ?

 

I tried changing the contact_us and instead of it using $http_post_vars i changed it to $_GET['varname'] and nothing really worked.

 

any major difference in them ?

 

Thanks.

Posted

GET and POST are two different methods to transfer variables. You have to use one or the other to pass a variable. You can't send with POST and catch with GET (or vice versa). osCommerce defaults to using POST.

 

Good luck,

Matt

Posted
any major difference in them ?

 

$_GET is only compatible with versions of PHP after 4.2.0 I believe were $HTTP_GET_VARS is compatible across all versions.

Mark Evans

osCommerce Monkey & Lead Guitarist for "Sparky + the Monkeys" (Album on sale in all good record shops)

 

---------------------------------------

Software is like sex: It's better when it's free. (Linus Torvalds)

Posted

To learn more about the modern approach to PHP's Predefined Variables read this:

PHP manual page

 

 

In short to replace $http_post_vars use $_POST['varname']

 

Good Luck,

John

Posted

the reason for asking is that my sample_request.php page works nicely when you know what you want :

 

$fullname=$HTTP_POST_VARS['NAME'];

   $fulladdress=$HTTP_POST_VARS['ADDRESS'];

   $fullcity=$HTTP_POST_VARS['CITY'];

   $fullstate=$HTTP_POST_VARS['STATE'];

   $fullpostcode=$HTTP_POST_VARS['POSTCODE'];

   $fullcountry=$HTTP_POST_VARS['COUNTRY'];

   $fulltelephone=$HTTP_POST_VARS['TELEPHONE'];

   $fullemail=$HTTP_POST_VARS['email'];

 

but if you don't know what you want, and you just want to receive everything, is there a way to do this ?

 

the drop down that i create, are random (code from product_info.php) and i want to be able to get them.

 

so is there a way to receive all the HTTP_POST_VARS at once, then somehow tokenize it or somthing...?

 

thanks.

reference: http://www.discountlanyards.com/sample_req...equest.php2.txt

Posted

I think I am very close to solving it.

http://www.discountlanyards.com/sample_request.php (online)

http://www.discountlanyards.com/sample_req...equest.php3.txt (code)

My email now displays this:

 

Name:  

         Lucy Lue  

Address:  

         15467 Lanley St.  

City:  

         London  

State:  

         CA  

PostCode:  

         91893  

Country:  

         dk  

Telephone:  

         555-123-4567

Email:  

         [email protected]  

Comments:  

         hello.  

Lanyard Width:  

         

Lanyard Color:  

         

Badge End Fitting:  

         

Breakaway Connector:  

         

Clamp or Bead:  

         

Quick Release Buckle:  

         

Imprint 1 or 2 sides:  

         

Type of Imprint:  

         

1st Color Imprint:  

         

2nd Color Imprint:

 

If you notice, then you will see that just the answeres or what they chose r not being displayed.....

 

Please give me some ideas.. i hate not being able to solve problems...

 

Thanks.

Posted

foreach($HTTP_POST_VARS as $key => $value) statement may do what you want.

 

I'm not sure that this is what you want to do though. In particular, I don't understand the statement:

the drop down that i create, are random (code from product_info.php) and i want to be able to get them.
Get what? Randomly selected from what? The drop down box itself will have a name and you will get the results by referencing something like $HTTP_POST_VARS['name_of_drop_down']. Unless I am totally misunderstanding what you are saying.

 

Good luck,

Matt

Posted

Here is what i'm doing.

i am trying to extend the functionality of the contact_us page to create a form for a customer to order a sample product. Thus i am incorporating the contact_us page and the product_info.php page (the code that generates the drop downs) to create the sample_request page.

 

I tried inserting what you gave me, and here is the result from my email:

Lucy LUe

1000 Oakdale ave.

Okland

Ok

227711

MARS

99223333333333

[email protected]

Array

hello.

52

3

 

the code:

foreach($HTTP_POST_VARS as $key => $value)

       {

         $mailcontent .=  $value . "n" ;

 

       }

 

the problem here is as such:

most important)

this imformation is meaningless:

     Array

hello.-except me

52

3

 

if you go to the webpage, you will see that there are soem product options. However, after selecting some product options and filling in the rest of the info, you are sent the above information. My dilema is, where is the information about the options that they have selected ? All i see is something that is 52 and 3 which are actually their product_option_id but then where are the rest, and why am i being given their product_option_id and not the product_option_value ? - the thing that they chose.

 

example from the online link below:

 

Breakaway Connector: has the following values:

solid strap

breakaway connector

velcro connectors.

 

if i chose the 2nd value, breakaway connector, then why doesn't this show up in the email, with the rest of the product_option choices that i've maade?

 

I hope that makes sense

 

Thanks.

 

http://www.discountlanyards.com/sample_request.php (online)

http://www.discountlanyards.com/sample_req...equest4.php.txt (code)

Posted

The product options are being bassed in the "id" array. You are not seeing them because you are not expanding the array. To get a better idea change:

 

$mailcontent .= $value . "n" ;

 

to;

 

$mailcontent .= $key . "=" . $value . "n" ;

 

Then instead of getting Array you will get id = Array

 

And may I suggest that you change to using $_POST as opposed to $HTTP_POST_VARS

 

Good Luck,

John

Posted

thanks for the reply John,

 

I tried that and here is what i got:

 

NAME=Lucy

ADDRESS=1000 Oakdale ave.

CITY= smallville

STATE=ca

POSTCODE=227711

COUNTRY=Danmark

TELEPHONE=99223333333333

[email protected]

id=Array

enquiry=please work

x=59

y=10

 

X ? Y ?

59 ? 10 ? these seem to be the production_option_values

- What happen to the rest of them ?

- And why products_options_values_id ? and not the products_options_values_name

 

???

 

Thanks.

foreach($_POST as $key => $value)

{

$mailcontent .= $key . "=" . $value . "n" ;

}

 

http://www.discountlanyards.com/sample_request.php (online)

http://www.discountlanyards.com/sample_req...equest4.php.txt (code)

Posted

You are getting painfully close, I do not know where the x and y values are coming from. But, lets not get sidetracked from your quest. As you see there is a line "id=Array." This is PHP's way of letting you know that a particular variable is actually an array of values. That is, the array "id" contains all of the info in which you are interested.

 

You just have to expand this variable to see its contents. A rather messey way to see the whole thing would be to use the print_r() function. I assume you have installed the very excellent chm version of the php_manual.

 

English verion of the On-Line PHP Manual

print_r() function

 

Happy coding,

John

Posted

thank john for the words of encouragement and your help.

 

heres what i got:

 

code:

$mailcontent = "";

/*

foreach($_POST as $key => $value)

{

$mailcontent .= $key . "=" . $value . "n" ;

}

*/

 

$mailcontent .= "nnn" ;

$mailcontent .= print_r ($value);

 

email:

 

 

1

 

 

any thougths?

Posted

I even tried this

 

Code:

foreach($_POST as $key => $value)

{

$mailcontent .= $key . "=" . $value . "n" ;

$mailcontent .= "calling function: " . print_r ($value) . "nn";

}

 

EmaiL:

NAME=Lucy LUe

calling function: 1

 

ADDRESS=1000 Oakdale ave.

calling function: 1

 

CITY= smallville

calling function: 1

 

STATE=NV

calling function: 1

 

POSTCODE=227711

calling function: 1

 

COUNTRY=dk

calling function: 1

 

TELEPHONE=99223333333333

calling function: 1

 

[email protected]

calling function: 1

 

id=Array

calling function: 1

 

enquiry=tell me something

calling function: 1

 

x=59

calling function: 1

 

y=12

calling function: 1

 

what to doo......

Posted

Have you tried

$mailcontent .= print_r($_POST);

 

You see $_POST is an array as is $key when it becomes == "id"

 

Note: When you finish this program you should understand associative arrays :)

 

John

Posted

try this:

while(list($key,$value) = each($_POST)){

  $parent = $key;

  if(is_array($value)){

     while(list($key,$val) = each($value)){

        $mailcontent .= $parent."[".$key."] = ". $val. "n";

     }

  }else {

     $mailcontent .= $key . "=" . $value . "n";

  }

}

 

Hope this helps as I am off for a week

John

Posted

Thanks to every1.

I was able to get it working fine.

Thanks to all that helped out.

 

I am going to try to add error handleing features, if i get time.

 

 

Good day.

  • 7 years later...
Posted

when HTTP_GET_VARS and HTTP_POST_VARS are deprecated long ago but why oscommerce is still carrying it even in its latest version.

please help me out ...............

have a nice day !!

Posted

Rather than extensively rewrite osC to use only $_POST and $_GET, the developers chose to leave $http_post_vars and $http_get_vars alone, and simply emulate by copying $_POST into $http_post_vars and ditto for $_GET. There is an "emulation layer" to do this, when PHP no longer creates $http_*_vars arrays. This lets osC keep running on old versions of PHP that do not have $_POST and $_GET.

Archived

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

×
×
  • Create New...