Connecting Tech Pros Worldwide Forums | Help | Site Map

Why wont this access an array???

Nick
Guest
 
Posts: n/a
#1: Jul 16 '05
Can someone please tell me how to access elements from a multiple
selection list? From what ive read on other posts, this is correct. I
keep getting an "Undefined variable" error though...

Form page********************************************** **************
<form action="/process.php" method="get" name="formOne" id="formOne">
<select name="owner[]" size="6" multiple id="owner[]">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>


Process page********************************************** ************
for($i=0; $i < count($owner); $i++) {
echo $owner[$i];
}

Thanks! -Nick

Marcus
Guest
 
Posts: n/a
#2: Jul 16 '05

re: Why wont this access an array???


Nick wrote:
[color=blue]
> Process page********************************************** ************
> for($i=0; $i < count($owner); $i++) {
> echo $owner[$i];
> }
>
> Thanks! -Nick[/color]

replace echo $owner[$i];

with

echo $_GET["owner"][$i];

- Marcus


Marius Mathiesen
Guest
 
Posts: n/a
#3: Jul 16 '05

re: Why wont this access an array???


Nick wrote:[color=blue]
> Can someone please tell me how to access elements from a multiple
> selection list? From what ive read on other posts, this is correct. I
> keep getting an "Undefined variable" error though...
>
> Form page********************************************** **************
> <form action="/process.php" method="get" name="formOne" id="formOne">
> <select name="owner[]" size="6" multiple id="owner[]">
> <option value="one">one</option>
> <option value="two">two</option>
> <option value="three">three</option>
> </select>
> <input type="submit" name="Submit" value="Submit">
> </form>[/color]
[color=blue]
> Process page********************************************** ************
> for($i=0; $i < count($owner); $i++) {
> echo $owner[$i];
> }[/color]

Just a hunch... Have you defined the variable $owner? If not, you are
probably depending on register_globals to being "on", which it may not
be in your system. Try using the following:
$owner = $_GET["owner"];
before your for... loop.

HTH
--
Marius

Closed Thread