i have just created one form that have some input fields with the same name . i want store all those value in one variable after submitting a form .
the code is
<div class="selectContainer">
<label>Number Of Person:</label>
<select id="ddTest" name="person">
<option value="">select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="hidden is1">
<a href="#" class="remove" rel="1">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is2">
<a href="#" class="remove" rel="2">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is2">
<a href="#" class="remove" rel="2">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is3">
<a href="#" class="remove" rel="3">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is3">
<a href="#" class="remove" rel="3">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is3">
<a href="#" class="remove" rel="3">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
<a href="#" class="remove" rel="4">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
<a href="#" class="remove" rel="4">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
<a href="#" class="remove" rel="4">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is4">
<a href="#" class="remove" rel="4">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
<a href="#" class="remove" rel="5">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
<a href="#" class="remove" rel="5">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
<a href="#" class="remove" rel="5">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
<a href="#" class="remove" rel="5">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>
<div class="hidden is5">
<a href="#" class="remove" rel="5">remove</a>
<label>Name</label>
<input type="text" name="name" >
<label>Age</label>
<input type="text" name="age" >
</div>`
how to store this value in one variable .? please help i am new to php
$name = $_POST['name'];
$age = $_POST['age'];
for($l=0; $l < count($name); $l++)
{ //your condition
}
don't forget to add this in your html
<label>Name</label>
<input type="text" size="20" name="name[]" id="name" >
</td>
<td>
<label>Age</label>
<input type="text" size="20" name="age[]" id="age" >
</td>
Create an array using []
for all similar names:
<input type="text" name="name[]" >
<input type="text" name="age[]" >
And then you can iterate over them:
for($i = 0; $i <= count($_POST['name']); $i++) {
echo $_POST['name'][$i] . "<br>";
echo $_POST['age'][$i] . "<br>";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With