Page 1 of 1

passing variables

Posted: Wed Jun 04, 2003 2:16 pm
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

Posted: Wed Jun 04, 2003 3:20 pm
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&...