Forum Moderators: coopster

Message Too Old, No Replies

Retrieving URL parameters - PHP, Dreamweaver MX

PHP, Dreamweaver MX, URL, variables, parameters

         

addictive

2:38 am on Dec 5, 2002 (gmt 0)

10+ Year Member



Im currently using Dreameaver MX, with a MySQL database and PHP scripted pages. My goal is to provide pricing based on the users country selection on the first page. I currently have a form on the first page with a list that is called varCountry, and I have created the URL variable varCountry in Dreamweaver, the form's action is set to GET. On submit the page goes to URL home.php, and it appears to pass the desired varCountry value. The problem is, the home.php page doesnt require this variable, but when the user goes to the products.php page, this is where the value of varCountry is required to display either NZ pricing or US pricing. First, how do I make sure the value of varCountry is making it to the products page? Second, how do I display either pricing based on that value? Do I set the filter of the Price Recordset to filter varCountry? (It is currently filtering CategoryID, to show the right price for that product) OR do I use some sort of show region if behaviour.

I have been battling with this for a few days now, as I am new to PHP etc.
<snip>

If anyone can help or suggest somewhere to get the appropriate information you would have one very grateful New Zealander!

Thankyou

[edited by: jatar_k at 8:54 am (utc) on Dec. 5, 2002]
[edit reason] no url's please - thanks [/edit]

brotherhood of LAN

7:51 am on Dec 5, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello addictive new zealander :)

So if I can get this straight
1) the form and selected country is submitted on default.php
2) the target of the form is home.php

Then the products pages will contain a price depending on which country they selected.

Is this going to be a one off, or after the person selects their country they will see the products page again and again?

If its the latter, then you need a way for PHP to remember what country was submitted with the form.

One way to do it is to start a session
[php.net...]

Something like

session_register("country")

When someone submits the form, you can register what country they had chosen for the rest of their session(usually until they close their browser window)

That way, you can reference what country they had chosen on the first page without too much hassle.

So on home.php, at the top you could have something like.

<?php
session_register("country")
rest of script
?>

The $country variable should be available on every subsequent page the person clicks on.

addictive

8:12 pm on Dec 5, 2002 (gmt 0)

10+ Year Member



Thankyou for the reply LAN BRO, I did think of using a session variable...but what if the user doesnt have cookies enabled...and are there any other downfalls with using a session variable? Also...Do I select the PriceNZ and PriceUS from the record set then somehow hide one or the other depending on the users choice? How do you hide either one dependent on the value of that variable?

Thanks again...

brotherhood of LAN

8:30 pm on Dec 5, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might want to check out that link, it's not essential that someone has cookies enabled to start a session.

If you turn your browser to refuse cookies, the registered session is passed along in the url

you'll get something like this on each subsequent URL

page.htm?PHPSESSID=ccd3f70bb0e58c5258a3c0f16215412a

I'm assuming that since a form has to be filled, all your future pages are not made for search engine spiders, so even if there was a problem with the likes of Google and Sessions [webmasterworld.com], it won't be a problem for you? :)

//added
there is probably a better way to do it but that'll work ;)

addictive

8:44 pm on Dec 5, 2002 (gmt 0)

10+ Year Member



Thanks heaps BRO, Im looking into session variables now and trying it out, wish me luck! But...

Question: What would be the best way to show or hide the pricing based on the session variable? Can you do it in the recordset...or is there a show region option based on the value?

Thanks BRO

brotherhood of LAN

10:00 pm on Dec 5, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hide the price for a certain country?

just do an if statement

if($varCountry == 'US')
{
do your stuff
}
else
{
do the other stuff
}

maybe if you were calling the product information from a database you could call a country "1" and another "2" or the like and suck data out depending on the number.

i.e. if you dont want to show prices for two, then dont select it from the database.

hey, you could do it like that depending on the url.

ie if the person submits US then they go to domain.com/1.html or if they submit the other country go to 2.html.

Definetely a few ways to skin a cat :), as said there's probably better ways