0

I have an HTML/PHP form that lists multiple inputs in which users can change values. I have a PHP while loop create the fields like so:

...
$result = mysql_query($query);
while (list($a,$b,$c) = mysql_fetch_row($result))
{
  echo '<tr>';
  echo '<td>$a</td>';
  echo '<td><input name="b" type="text" value="'.$b.'"</input></td>';
  echo '<td><input name="c" type="text" value="'.$c.'"</input></td>';
  echo '</tr>';
}
...

For this example I can have multiple lines of a,b,c and want to get all of the values when I submit the form via POST. Only $b and $c are input values that can be changed. Do I create variables $a,$b,$c as arrays, and if so, how do I set that up so that all of the values will be stored?

A.L
  • 10,259
  • 10
  • 67
  • 98
Haris P
  • 47
  • 7

1 Answers1

0

submit your inputs with name like b[] & c[]

HTML

<input type="hidden" name="a[]" value="a_value" />
<input type="text" name="b[]" value="b_value" />
<input type="text" name="c[]" value="c_value" />

PHP

<?php  print_r($_POST['a']); ?>
<?php  print_r($_POST['b']); ?>
<?php  print_r($_POST['c']); ?>
Neverever
  • 15,890
  • 3
  • 32
  • 50
  • Why not something like `array[$i][a]` where `$i` is incremented? It will be easier to use with a `foreach` loop on each row, instead of columns (`$_POST['a']` will only contain `a`). – A.L Mar 29 '15 at 22:45
  • I assume the op wants to have $a, $b, $c as separate array – Neverever Mar 29 '15 at 22:50
  • This seems more complicated to handle it with PHP but you're right, that's what the OP asked. – A.L Mar 29 '15 at 22:51