By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

accessing multiple values for a variable

P: n/a
I'm creating a simple order form that allows visitors to order
photographs from an artist's web site. For each photo available for
sale, there is a checkbox whose name is "photo". The form uses post
to transfer data to a php form, where the visitor will enter name and
contact info.

When I try to access the posted information in the destination php
form, I only get the last photo selected. How do I access these
values if the user selected more than one photo?

--
Brian
follow the directions in my address to email me

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Brian wrote:
I'm creating a simple order form that allows visitors to order
photographs from an artist's web site. For each photo available for
sale, there is a checkbox whose name is "photo". The form uses post to
transfer data to a php form, where the visitor will enter name and
contact info.

When I try to access the posted information in the destination php form,
I only get the last photo selected. How do I access these values if the
user selected more than one photo?


Change the name for the checkbox to "photo[]" - that makes
$_POST['photo'] an array that you can look at.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #2

P: n/a
*** Brian wrote/escribió (Wed, 03 Dec 2003 22:17:03 GMT):
When I try to access the posted information in the destination php
form, I only get the last photo selected. How do I access these
values if the user selected more than one photo?


When PHP gets several form variables with the same name, each values
overrides the previous ones. You have two options:

* Give fields different names: photo01, photo02...
* Force an array: photo[], photo[]...

You can even mix both solutions ;-)

photo[1], photo[2]...

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.