Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Creating action of GET
Old 03-05-2005, 06:22 PM Creating action of GET
Audioz's Avatar
Skilled Talker

Posts: 87
Location: Birmingham
Trades: 0
Im trying to create an action of GET,looking something like the following:

$_GET[];
$country = ;
$resellerId = ;
$sitename = ;
$itemId = ;
$itemType = ;

Ive left the actual values out for this example,does it look correct or am i doing anything wrong there? Also i dont understand how i will make a link from this,Im trying to insert a hyperlink of "Buy Now" in the actuall area that i place that php,but i realise im misunderstanding something,could anyone put me right on this please?
Thanks
Audioz is offline
Reply With Quote
View Public Profile Visit Audioz's homepage!
 
 
Register now for full access!
Old 03-05-2005, 06:33 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
To put together a URL using get variables as they are called, you just append them onto the URL:

Code:
<a href="somepage.php?resellerId=14&amp;country=mongolia&amp;itemType=cheese">Buy Cheese in Mongolia!!</a>
Then in somepage.php you can read the values out of $_GET by indexing into it (it's just an array like an other in php):

PHP Code:
$country $_GET['country']; 
You should never have to assign TO the $_GET array - php generates it for you when someone clicks a URL with variables after the '?'.
You can of course use php to assemble a URL string with different variables in it, and send different links to the browser, but you should never need to set or change elements of the $_GET array directly.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-06-2005, 09:49 AM
Audioz's Avatar
Skilled Talker

Posts: 87
Location: Birmingham
Trades: 0
Hi 0beron

Thanks for replying,i understand the first part that you have explained about adding the get variables into the URL, but i dont understand the second part that you have explained
the following:

Then in somepage.php you can read the values out of $_GET by indexing into it (it's just an array like an other in php):


PHP Code:
$country = $_GET['country'];


Im not sure what i have to do with that part,where i put it,im still very new to PHP,i appreciate your help so far.
Thanks
Audioz is offline
Reply With Quote
View Public Profile Visit Audioz's homepage!
 
Old 03-06-2005, 10:44 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
OK - really basic example:

If you have a link:

<a href="example.php?variable1=hello">Click Here</a>

and a php file called example.php:

PHP Code:
<?php

$variable1 
$_GET['variable1'];
echo 
$variable1;

?>
Then if you click that link, you will see 'hello' printed on the screen. When I say 'indexing into an array', all I mean by that is putting something in between the '[' and the ']'. An array in php is just a list of things called keys and things called values. Each key has a value, and to find the value for a particular key you write $yourarray[key]. The key might be a string or a number or whatever. In the example above the key is the string 'variable1' and the value you get back is 'hello'.

$_GET is a special array that php provides, and you can use it anywhere in your scripts. So whenever you reach a point in your script where you need to put in the value from the URL, you can just write $_GET['varname'] where you replace 'varname' with whatever name was in the URL. PHP will evaluate that as the correct value from the URL and you're done
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-06-2005, 10:45 AM
Super Talker

Posts: 121
Trades: 0
the $_GET[] array, along with the $_POST[] array are associative arrays, so the varibles in them are accessed by using the varible name as the key.

i read, that with post and get, if you pass a varible, lets say, called country, you dont need to do $country = $_GET['country']; , you can just use $country am i right?
vegancoder is offline
Reply With Quote
View Public Profile
 
Old 03-06-2005, 10:52 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Quote:
Originally Posted by vegancoder
i read, that with post and get, if you pass a varible, lets say, called country, you dont need to do $country = $_GET['country']; , you can just use $country am i right?
You are indeed right, although this relies on your installation of php having register globals switched on. This is a possible security hazard, so some servers have it switched off. Even if it is switched on, it is a good idea to only deal with the $_GET and $_POST arrays since when you move your code to a server without register globals on, or your server switches it off, then your scripts won't suddenly break!
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-06-2005, 12:32 PM
Audioz's Avatar
Skilled Talker

Posts: 87
Location: Birmingham
Trades: 0
So after creating a URL using the variables,like the following:

<a href="#http://www.linktobillingpage.com/popup.php?country=uk&amp;resellerId=201054&amp;sit eName=ringtonesbase&amp;itemId=50001&amp;itemType= PolyRingtones&amp;">Buy Now</a>

I then place the following code somewhere on the page?

$country = $_GET['country'];
$resellerId = $_GET['resellerId'];
$siteName = $_GET['siteName'];
$itemId = $_GET['itemId'];
$itemType = $_GET['itemType'];

Is this correct and if so,where do i place the immediate above on the webpage?
Also i have a mysqldump file from the company im working with,and im advised to put this into an empty database of my own,am i correct in thinking that until the mysqldump file is in the correct place that the link to the billing popup wont work at all?
Audioz is offline
Reply With Quote
View Public Profile Visit Audioz's homepage!
 
Old 03-06-2005, 12:37 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
You will need to have your mySQL database set up and running before you can use it.

In your URL, you don't need the final &amp; - they are just used as separators so you don't need one on the end.

The code you have will work fine, and will fill in the values of your variables.

You can put it pretty much anywhere you like, so long as it comes before where you need to use them. Your pop up script can then use the variables to hunt for stuff in the database or echo stuff out to the browser so you can make your billing page look how you want.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-06-2005, 01:26 PM
Audioz's Avatar
Skilled Talker

Posts: 87
Location: Birmingham
Trades: 0
Thanks 0beron

Your an excellent help,i appreciate you taking the time to reply to my questions.
Audioz is offline
Reply With Quote
View Public Profile Visit Audioz's homepage!
 
Reply     « Reply to Creating action of GET
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.64800 seconds with 12 queries