Post text box array in PHP
23,039
Solution 1
<input type="text" name="array[]" />
<input type="text" name="array[]" />
<input type="text" name="array[]" />
<input type="text" name="array[]" />
print_r( $_POST['array'] );
Solution 2
<input type="text" name="ItemName[1][2]" >
<input type="text" name="ItemName[1][3]" >
<input type="text" name="ItemName[1][4]" >
$ItemNamesArray = $_POST['ItemName'][1];
foreach($ItemNamesArray as $item){
var_dump($item); //this will show you the value of each item
// do whatever you want to do (insert into a database, send an email, etc)
}
But I would not use a bidimensional array for this, only if ItemName is been used for another purpose on the same form.
Solution 3
<form method="post" name="myform">
<input type="text" name="array[]" Value="101"/>
<input type="text" name="array[]" Value="102"/>
<input type="text" name="array[]" Value="103"/>
<input type="text" name="array[]" Value="104"/>
<input type="submit" name="submit" Value="submit"/>
</form>
if(isset($_POST['submit'])){
foreach($_POST['array'] as $myarray) {
echo $myarray.'<br>';
}
OUTPUT
101
102
103
104
Author by
sqlchild
Making me.....will appear soon :) Work : PHP and MySQL are in my two hands, shaking my hands together, thus, INNER JOINING the two entities to output some good web applications Need to Say me Hi!....just post a comment on any of my SO post....I will be right there :)
Updated on August 15, 2020Comments
-
sqlchild over 3 years
I have text box values to be posted . How do I take it in a PHP array .
EDIT
--------------------------- <input type="text" name="ItemName[1][2]" > <input type="text" name="ItemName[1][3]" > <input type="text" name="ItemName[1][4]" > ------------------------------ $ItemNamesArray = $_POST[] ..... ????? What do I do in this step???
Please help.
-
pawel-kuznik about 12 yearsShould also write that he can access it via $_POST['array'][0], $_POST['array'][1], ... cause trick with [] will do an array in PHP.
-
sqlchild about 12 yearssir, i directly pasted the html which was hidden ,now i have recdtified the post ... please help now
-
sqlchild about 12 yearssir, i directly pasted the html which was hidden ,now i have recdtified the post ... please help now
-
s.webbandit about 12 yearsNot so good format. Can you change names of your
inputs
or it's impossible? -
Apolo almost 10 yearsOP does not talk about database
-
Apolo almost 10 yearsOP does not talk about database
-
Apolo almost 10 yearsThis will output '3', and does not give an array