Answer the question
In order to leave comments, you need to log in
How to get the order id to return to the page after deleting an order item?
Good evening!
Tell me, please, I encountered such a problem:
I create an order through the form, specify the name, cost, date, status. The data goes into the tb_orders table.
Next, I go to the order page and add order items inside the order through the form. The data goes into the tb_items table and is displayed on the order page. Everything works well here.
I need to add the functionality of deleting an order item. I also implemented this, everything is deleted from the database, BUT I can’t figure out how to make the transition after executing the script for deleting the position.
That is, how to get the order id in the deletion script file in order to switch to the same order from which the item was deleted? I pass the position id to the delete script using a GET request.
Delete script:
<?php
require_once '../config/connect.php';
$item_id = $_GET['id'];
$item_delete = "DELETE FROM tb_items WHERE `id` = '$item_id'";
$item_delete = mysqli_query($connect, $item_delete);
header('Location: ../order.php');
?>
<tbody>
<?php
foreach ($item_view as $item){
?>
<tr>
<td> <?= $item[2] ?> </td>
<td> <?= $item[3] ?> </td>
<td> <?= $item[4] ?> </td>
<td> <?= $item[5] ?> </td>
<td><a href="vendor/delete_item.php?id=<?= $item[0] ?>">Удалить</a></td>
</tr>
<?php
}
?>
</tbody>
<form action="vendor/create_item.php" method="POST">
<input name="id" type="hidden" value="<?= $order_view['id'] ?>">
<input name="item_name" type="text">
<input name="item_cost" type="text">
<input name="item_quantity" type="text">
<textarea name="item_tz"></textarea>
<p><button type="submit">Добавить</button></p>
</form>
<?php
require_once '../config/connect.php';
$order_id = $_POST['id'];
$item_name = $_POST['item_name'];
$item_cost = $_POST['item_cost'];
$item_quantity = $_POST['item_quantity'];
$item_tz = $_POST['item_tz'];
$item_create = "INSERT INTO tb_items (order_id, item_name, item_cost, item_quantity, item_tz) VALUES ('$order_id',
'$item_name', '$item_cost', '$item_quantity', '$item_tz')";
$item_create = mysqli_query($connect, $item_create);
header('Location: ../order.php?id=' . $order_id);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question