Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return form results using array 1

Status
Not open for further replies.

mrsbean

Technical User
Jul 14, 2004
203
US
I want to return the contents of a multi-select list box from a form using an array.

Code:
$size = count ($_REQUEST['AreasOfInterest']);

$p1 = $_REQUEST['AreasOfInterest[]'];

echo "<P>size: $size </p>";
$x = 0;

while ($x < $size) {
echo "<p> Array Value $x = $p1[$x] </p>";
$x++;
}

Arrays scare me - not really sure how they work. The code above returned the following:

size: 4

Array Value 0 =

Array Value 1 =

Array Value 2 =

Array Value 3 =

I'm not getting the text value I was seeking following the equal sign. What am I doing wrong?

Thanks in advance.

MrsBean
 
The interior brackets in this line:

$p1 = $_REQUEST['AreasOfInterest[]'];

don't make sense. If you mean to reference an element of $_REQUEST['AreasOfInterest'], then that is done as $_REQUEST['AreasOfInterest'][0], $_REQUEST['AreasOfInterest'][1], $_REQUEST['AreasOfInterest'][2], etc.

Also, I recommend strongly against using $_REQUEST. It is more secure to reference $_GET and $_POST for GET- and POST-method input, respectively. Since $_REQUEST is an amalgam of $_GET, $_POST and $_COOKIE, $_REQUEST shares some of the problems of setting register_globals() to "on". See


Want the best answers? Ask the best questions! TANSTAAFL!
 
Omit the sharp brackets [ignore][][/ignore] from your request, then it should work :

Code:
$p1 = $_REQUEST['AreasOfInterest'];

;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top