(Как простая корзина покупок. После получения указанных c данных из таблицы базы данных, называемой продуктами, и после нажатия кнопки «Добавить в корзину», где пользователь может видеть свои товары, мне нужно вставить данные заказа пользователя в другая таблица базы данных называется order, тогда мне нужно уменьшить количество заказанного продукта из таблицы product)
вот код
Код формы поиска где пользователь может найти продукт и щелкнуть поиск
<form method="POST" action="index.php" >
<div class="input-group">
<input type="text" class="form-control search-input" placeholder="Search" name="keyword3" required="required"/>
<button type="search" class="btn btn-light search-button" name="search3"><i class="fas fa-search text-danger"></i></button>
</form>
The Php code that allow the retrieving of the searched data on the page
<?php
if (isset($_POST['search3'])) {
$keyword3 = $_POST['keyword3'];
$query = mysqli_query($db, "SELECT * FROM `pharm1products` WHERE `Name` LIKE '%$keyword3%' ORDER BY `Name`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
$I = base64_encode( $fetch['Image'] );
?>
**The form where The data is retrieved from the database after clicking on search**
<form class="" method="post" action="index.php?action=add&id=<?php echo $fetch["id"]; ?>">
<div class="sr bg-dark" >
<!-- style="border:1px solid #333; background-color:#f1f1f1; border-radius:5px; padding:16px; float:left" align="center"> -->
<h5 class="text-light ss"> </h5>
<h5 > <?php echo'<img src="data:image/jpeg;base64,'.base64_encode( $fetch['Image'] ).'"style="width:200px;height:200px;float:right">';?></h5>
<h3 class="text-light ss"> <i>Product Name : </i><br> <h2> <strong class="text-warning text-center"> <?php echo $fetch['Name']?></strong></h2> </h3>
<h5 class="text-light ss"> <i>Product Type : </i><br> <h4 class="text-warning text-center"> <?php echo $fetch['Type']?></h4> </h5><br>
<h5 class="text-light ss"> <i> Product price:</i> <h4 class="text-center text-warning"><?php echo $fetch["Price"]; ?></h4> </h5> <br>
<h5 class="text-light ss" > <i> Product Quantity:</i><h4 class="text-warning text-center"> <?php echo $fetch["Quantity"]; ?></h4></h5>
<input style="margin-bottom: 10px;max-width: 250px;" type="text" name="Quantity" value="" class="form-control" placeholder="Enter the quantity you want" />
<input type="hidden" name="hidden_name" value="<?php echo $fetch["Name"]; ?>" />
<input type="hidden" name="hidden_price" value="<?php echo $fetch["Price"]; ?>" />
<input type="submit" name="add_to_cart" style="margin-top:5px;" class="btn btn-outline-warning" value="add product" />
таблица, в которой отображаются добавленные продукты
<form method="post" action="index.php?action=add&id=<?php echo $fetch["id"]; ?>">
<h3 class="text-muted text-center mb-3 "> Your Order Details</h3>
<div class="table-responsive">
<table class="table table-bordered" >
<tr>
<th class="text-warning bg-dark" width="30%">Item Name</th>
<th class="text-warning bg-dark" width="20%">Quantity</th>
<th class="text-warning bg-dark" width="20%">Price</th>
<th class="text-warning bg-dark" width="10%">Total</th>
<th class="text-warning bg-dark" width="10%">Action</th>
</tr>
<?php
if(!empty($_SESSION["shopping_cart"]))
{
$total = 0;
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
?>
<tr>
<td class="text-uppercase"> <strong><?php echo $values["item_name"]; ?></strong></td>
<td> <?php echo $values["item_quantity"]; ?> </td>
<td><?php echo $values["item_price"]; ?></td>
<td><?php echo number_format((int)$values["item_quantity"] * (int)$values["item_price"]);?></td>
<td><a href="index.php?action=delete&id=<?php echo $values["item_id"]; ?>"><span class="text-danger">Remove</span></a></td>
<button type="button" class="btn btn-outline-info mb-3 ml-auto mr-auto" name="Submit">Submit Order</button>
</tr>
<?php
$total = (int)$total + ((int)$values["item_quantity"] * (int)$values["item_price"]);
}
?>
<tr>
<td colspan="3" align="right">Total</td>
<td align="right">$ <?php echo number_format($total); ?></td>
<td></td>
</tr>
<?php
}
?>
</table>
код. php эта страница включает php коды таблицы
<?php
include("connection.php");
if(isset($_POST["add_to_cart"]))
{
if(isset($_SESSION["shopping_cart"]))
{
$item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
if(!in_array($_GET["id"], $item_array_id))
{
$count = count($_SESSION["shopping_cart"]);
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["Quantity"]
);
$_SESSION["shopping_cart"][$count] = $item_array;
}
}
else
{
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["Quantity"]
);
$_SESSION["shopping_cart"][0] = $item_array;
}
}
if(isset($_GET["action"]))
{
if($_GET["action"] == "delete")
{
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
if($values["item_id"] == $_GET["id"])
{
unset($_SESSION["shopping_cart"][$keys]);
}
}
}
}
?>
Соединение. php, где соединение базы данных
<?php
$db = mysqli_connect('localhost', 'root', '', 'tester') or die(mysqli_error());
if(!$db){
die("Error: Failed to connect to database");
}
?>
Пожалуйста, помогите я в моем дипломном проекте, это самая важная часть этого, пожалуйста, мне нужна ваша помощь, я знаю, что я не совершенен в кодировании, но я уверен, что я получу идеальный ответ