Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Newbie to PHP needs help with querystrings.

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Newbie to PHP needs help with querystrings.

Postby amerrigan » Thu Apr 10, 2003 8:45 am

Hi!

Firstly I'm new to PHP and have only moved from ASP in the last week.

I am coding a site in PHP for a client and have no understanding of PHP querystrings. I wish to create a referral incentative for customers, in order for the system to pick up referrers I use a querystring eg. http://domain.com/default.php?ref=123456.

I have tried using:

<?php $_GET['ref']; ?>

and/or

<?php $_GET['ref']; echo $ref;?>

which works fine when there is a querystring present. However without a query in returns an "Undefined index" error.

I need either a quick fix to force a default referrer code ie 123456 when no querystring is present (eg http://domain.com/ or http://domain.com/default.php). Or a need new way of thinking around this.

Any examples are welcome.

HELP!

Tony
amerrigan
New php-forum User
New php-forum User
 
Posts: 6
Joined: Thu Apr 10, 2003 8:25 am

Postby Skeletor » Thu Apr 10, 2003 9:02 am

if you only want to print it if it is populated, you can do one of the following:

if(isset($_GET['ref']))
print

or I usually do this to make sure it is not empty:

if(!empty($_GET['ref']))
print
Skeletor
New php-forum User
New php-forum User
 
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio

Postby amerrigan » Thu Apr 10, 2003 9:11 am

Sorry to sound thick, how would I implement this? Like I said I'm new to PHP and am only really versed with ASP and VBScript.

I need to be able to pass the querystring to all pages and use something like the following in every link on site.

<A href="default.php?ref=<?php $_GET('ref'); echo $ref;?>">home</a>
amerrigan
New php-forum User
New php-forum User
 
Posts: 6
Joined: Thu Apr 10, 2003 8:25 am

Postby amerrigan » Thu Apr 10, 2003 9:21 am

It's ok I worked it out!

Thanks Skeletor this was exactly what I needed!

<?php if(!empty($_GET['ref'])) echo $ref;?>
amerrigan
New php-forum User
New php-forum User
 
Posts: 6
Joined: Thu Apr 10, 2003 8:25 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.