passing variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dirkvu
Forum Newbie
Posts: 1
Joined: Wed Jun 04, 2003 2:16 pm

passing variables

Post by dirkvu »

Hey,

I want to pass multiple variables with the get method. The names of the variables are the same.
It works with one variable:

url = http://www.mysite.com/testing.html?name=jon

In my code I write : $variabele = $_GET["name"];

But now!!!!!:

http://www.mysite.com/testing.html?name=jon&name=mike

How can I put the names jon and mike (or even more names) in variables?
If I use: $name = $_GET["name"] , I only get the last name.

I also could write my program that I'll send this:

http://www.mysite.com/testing.html?name1=jon&name2=mike&...

But than I need to know how many variables I'm receiving. If I write:
$variable5 = $_GET["name5"]
and there's no name5, I get a warning. How can I know how many variables there are?

Can someone help me with this?

Thanx
Dirk
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<html>
	<body>
		<pre><?php print_r($_GET); ?></pre>
		<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			<input type="text" name="name[]" />
			<input type="text" name="name[]" />
			<input type="submit" />
		</form>
	</body>
</html>
php will handle parameters paramName[]=value like php-code

Code: Select all

<?php $paramName[]='value'; ?>
so the value will be appended to the array $paramName (or $_GET['paramName']).
For links you have to urlencode [ and ] which results in
http://www.mysite.com/testing.html?name ... 5B%5D=mike&...
Post Reply