So I am trying to get a auto_incremented ID from a table and put it into another table. The table I'm trying to get the ID from is a grocery list, therefore the amount of items can be added to/removed from. I'm trying to place that ID into an 'item_id' column in an inventory table.
$item_row = $connect->query("SELECT * FROM `items` WHERE **[ROW #]**=$index");
$item_ids = mysqli_fetch_assoc($item_row);
$item_id = $item_ids['id'];
$connect ->query("INSERT INTO `inventory`(`id`,`item_id`,`recipient_id`,`debtor_id`,`amount`) VALUES ('NULL','$item_id', '$user_contrib','$debtor','$price')");
The item that is selected is located in an HTML table
foreach ($item_array as $id_array){ ?>
<td><?php echo $item_array[$index]; ?></td>
<td> <?php echo $quantity_array[$index]; ?> </td>
<td><?php echo $price_array[$index];
<?php echo $id_array[$index];?>
<form class="omb_loginForm" action="inc/contribute_item.php" method="POST">
<input type='hidden' name='item_inventory_id' value="<?= $item_inventory_id[$index]; ?>">
<input type='hidden' name='item_name' value="<?= $item_array[$index]?>">
<input type='hidden' name='item_price' value="<?= $price_array[$index]?>">
<input type='submit' name="submit" value"submit">
</form>
</td><?php
$index++;
} ?></tr>
I don't know if the HMTL code will help with anything. But the item being selected is indexed.
UPDATE
I changed the first input of the form to $id_array[$index] which gets the value of the id from the items
table. And then when I pass it and echo it contribute_item.php it prints, what appear to be, random letters. Both upper and lower-case. ID is an int, but would the auto_increment of the id have any affect on the format?
<input type='hidden' name='item_id' value="<?= $id_array[$index]; ?>">
Solved it. I failed to provide code that I didn't think was necessary. In the file I declare all of the arrays I declare id_array as its own variable, but then when I run it through the for loop I was adjusting the value. I had $item_array approaching the $id_array. This was affecting the value of $id_array in the loop. So when I wanted to submit this
foreach ($item_array as $id_array) ...
I needed to change it to
foreach ($item_array as $id_arrays)...
<input type='hidden' name='item_id' value="<?= $id_array[$index]; ?>">