I have some PHP code that checks a MYSQL database using MySQLi and outputs all of the 'stock' type into a form with a while statement:
$result = mysqli_query($link,"SELECT name FROM items WHERE type='stock' ORDER BY name");
echo '<table style="text-align:center;"><tr><th>Name</th><th>Quantity</th><th>Use</th>';
while($item = mysqli_fetch_array($result)){
echo '<tr><form action="chooseProduct" method="POST"><td>' . $item['name'] . '</td><td><input type="number" name="amount[]"></td><td><input type="checkbox" name="stock[]" value="' . $item['name'] . '"></td></tr>';
}
echo '<tr><td rowspan="3" colspan="3"><input type="submit" value="Select"></td></tr></form></table>';
I then need to be able to select the stock that I wish to use and click on select to send me to the "chooseProduct" page where there I should then be able to use the data 'amount' and 'stock' in an array form. However, when using POST to retrieve these values on the chooseProduct page by doing the following:
$stock = $_POST['stock'];
$amount = $_POST['amount'];
I get the error as follows:
Notice: Undefined index: stock in C:\xampp\htdocs\production\chooseProduct\index.php on line 59
Notice: Undefined index: amount in C:\xampp\htdocs\production\chooseProduct\index.php on line 60
The checkbox is definitely checked, so what could be causing this error?