Okay, so I have a PHP array pulling from a mysql table. The array is generated based on the items in a table where items are frequently added and deleted. I have a button next to the item name, "Submit." I want the button to identify with the item that is in the same index. It will then pass the item submitted item to a new table.
<form class="omb_loginForm" action="inc/contribute_item.php" autocomplete="off" method="POST">
<?php
$item_array;
$index = 0;
$index_2 = 1;
$r = "r";
$b="b";
foreach ($item_array as $id_array){ ?>
<tr id="<?php echo $r.$index_2; ?>">
<td><?php echo $item_array[$index] ?></td>
<td> <?php echo $quantity_array[$index]; ?></td>
<td> <?php echo $price_array[$index];
$selectedItem = $item_array[$index]; ?>
<input type='hidden' name='hidden' value='<?php $selectedItem ?>'>
<input type='submit' name='submit' value"submit">
</form> </td>
<?php $index++;
$index_2++; ?>
</tr>
Here is the PHP:
if ($_POST['submit']) {
$connect = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$user_contrib = $_SESSION['first_name'];
$selected = $selectedItem;
$connect->query("UPDATE `items` SET `purchased_by` = '$user_contrib' WHERE `name` = '$selected'");
}