This is how I display the entire array:
print('<pre>');
print_r($_POST);
print('</pre>');
The Array :
Array
(
[Prod] => Array
(
[0] => Array
(
['id'] => 1
['name'] => value2
['desc'] => value
['cost'] => 500.0000
['sell_price'] => 1500.0000
['quant'] => 9
['vendor'] => 1002
['last_update'] => Joe Lee
)
[1] => Array
( ... )
['btnUpdate'] => Sumbitted Form
)
)
but if I change it to $_POST['Prod']['btnUpdate']
it throws an error..
This is how the Error if I try to access "btnUpdate"
Notice: Undefined index: btnUpdate in C:\xampp\htdocs\Projects\Upwork\dharn\scratch\phase2\controller\update_Product.php on line 6
I've read the duplicate but as you can see the entire array of $_POST
.. in my knowledge $_POST['Prod']['btpUpdate']
should exist but NO it does not, php can't find it...
UPDATE
i've made a type mistake on creating the array..
while($row = mysqli_fetch_array($result)){
?>
<tr>
<td>
<input type="text" hidden name="Prod[<?php echo $x?>]['id']" value="<?php echo $row['id']?>">
<?php echo $row['id']?>
</td>
<td>
<input type="text" name="Prod[<?php echo $x?>]['name']" value="<?php echo $row['name']?>">
</td>
<td>
<input type="text" name="Prod[<?php echo $x?>]['desc']" value="<?php echo $row['description']?>">
</td>
<td>
<input type="text" name="Prod[<?php echo $x?>]['cost']" value="<?php echo $row['cost']?>">
</td>
<td>
<input type="text" name="Prod[<?php echo $x?>]['sell_price']" value="<?php echo $row['sell_price']?>">
</td>
<td>
<input type="text" name="Prod[<?php echo $x?>]['quant']" value="<?php echo $row['quantity']?>">
</td>
<td>
<select name="Prod[<?php echo $x?>]['vendor']">
<?php echo Generate_Vendor($row['Vendor_name']); ?>
</select>
</td>
<td>
<input type="text" hidden name="Prod[<?php echo $x?>]['last_update']" value="<?php echo $row['Employee_name']?>">
<?php echo $row['Employee_name']?>
</td>
</tr>
<?php
$x++;
}
?>
</table>
<button type="submit" name="Prod['btnUpdate']" value="'Sumbitted Form'"> Update Product </button>
ANSWER
in a code like this name="Prod[<?php echo $x?>]['id']"
right in the id part... that's the typo.. you should not put ( ' ' ) single-qoute on the array because it will generate an array like the one above where you could not access it because it is a string inside the key...
in simple words you should not create an array with a stringed key