473,238 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

How PHP $_POST gets the multiple values from a HTML form?

RC
I am try test a simple HTML form with PHP

<form method=POST action="testing.php">
Cat <input type="checkbox" name="pet" value="cat">
Dog <input type="checkbox" name="pet" value="dog">
Pig <input type="checkbox" name="pet" value="pig">
<br>
<select name="dates" multiple>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>

When I checked cat, pig and selected Tuesday and Saturday from the form
and click submitt

My testing.php is

<?php
$pet = $_POST['pet'];
$dates = $_POST['dates'];

print_r($pet);
var_dump($dates);
?>

The $_POST['pet'] and $_POST['dates']
are NOT return as array nor multiple
strings seperated with a comma.
It only return the LAST string I have
checked and/or selected.

How do I get the multiple values from the
checkbox and the multiple select from a
HTML form in PHP?

Thank Q very much in advance!
Jul 17 '05 #1
3 78448
RC
RC wrote:
I am try test a simple HTML form with PHP

<form method=POST action="testing.php">
Cat <input type="checkbox" name="pet" value="cat">
Dog <input type="checkbox" name="pet" value="dog">
Pig <input type="checkbox" name="pet" value="pig">
Never mind, I found the solution
In HTML file form need to changed to

Cat <input type="checkbox" name="pet[]" value="cat">
Dog <input type="checkbox" name="pet[]" value="dog">
Pig <input type="checkbox" name="pet[]" value="pig">
<br>
<select name="dates" multiple>
and need to changed to
<select name="dates[]" multiple>

<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>

When I checked cat, pig and selected Tuesday and Saturday from the form
and click submitt

My testing.php is

<?php
$pet = $_POST['pet'];
$dates = $_POST['dates'];
Then in PHP need to changed to

$pet = array($_POST['pet']);
$dates = array($_POST['dates']);
print_r($pet);
var_dump($dates);
?>

Jul 17 '05 #2
On Wed, 18 May 2005 09:34:36 -0400, RC <ra**********@nospam.noaa.gov>
wrote:
Try amending the slect tag to include a set of square brackets after
the name like this:

<select name="dates[]" multiple>

That should then give you the selected elements in an array.

hth

C
Jul 17 '05 #3
On Wed, 18 May 2005 09:43:32 -0400, RC wrote:
Then in PHP need to changed to

$pet = array($_POST['pet']);
$dates = array($_POST['dates']);


No way dude, remove the array(), then $pet will still be an array
because $_POST['pet'] is. By the way, no need to use a local variable
like $pet, you could just use $_POST['pet']. Try print_r($_POST);
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: r0adh0g | last post by:
I am attempting to build a primitive search form on my site. It is searching an Access Database Table and comparing on field in the database to a field passed from the form. Works great if only...
16
by: Philippe C. Martin | last post by:
Hi, I am trying to change the data in a form field from python. The following code does not crash but has no effect as if "form" is just a copy of the original html form. Must I recreate the...
3
by: Kathy | last post by:
Can someone help me with the code to take the data in four fields on an HTML form and add it to a table in a database on an intranet. Thanks to all who help! Kathy
9
by: Bob Malcoprs | last post by:
Hi, I want to get all the selected values of a listbox in several labels.. With this code here below, when i click on e.g. "option 2", i get '2' in label2. That's ok. But if i then click on...
0
by: pplers | last post by:
Is it possible to do this with VB6, instead of .NET ??? If it can be done, how ???
2
by: kuchel | last post by:
Hi I have a table which looks typically like this:- ColA COLB 2370 2875 2370 3194 2376 3108 2417 2437 2539 2774 2539 2732 2539 3240
2
by: Danielle | last post by:
Hello all, I'm pretty new to asp.net, I've to do a quick port to ASP.net I've got a problem I cannot solve: cannot find anything helpfull on the web. I've got an HTML form generated from a...
2
by: =?Utf-8?B?Q29yeSBKLiBMYWlkbGF3LCBCZXlvbmQwMS5jb20= | last post by:
Hello! I need to retrieve POST information from an HTML form into my VB ASP.net 2008 web form. My simple html form is: <form action="webform1.aspx" method="post" name="Form1"> <input...
4
by: Akpo | last post by:
Hi all...i am working on a project to capture students' data for an educational institution. I want to have a form that allows multiple student records to be filled in at once..e.g(this is the form):...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.