473,322 Members | 1,846 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,322 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 78524
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: 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...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.