I have a problem, when I click to other -/+ in new row, the old row return initial value. How can I fix it?
<?php
$arr = array(1, 2, 3);
for ($i = 0; $i < 3; $i++) {
$arr[$i] = isset($_POST["item".$i]) ? $_POST['item'.$i] : $arr[$i];
if (isset($_POST['incqty'.$i])) {
$arr[$i] += 1;
}
if (isset($_POST['decqty'.$i])) {
$arr[$i] -= 1;
}
}
?>
<?php
for ($i = 0; $i < 3; $i++) {
?>
<form method='post' action='<?= $_SERVER['PHP_SELF']; ?>'>
<td>
<button name='decqty<?php echo $i; ?>'>-</button>
<input type='text' size='1' name='item<?php echo $i; ?>' value='<?= $arr[$i]; ?>' />
<button name='incqty<?php echo $i; ?>'>+</button>
</td>
</form>
<?php
}
?>
change value when end click other row