PHP在线商店,循环按钮和数据库


PHP online store, looping buttons & databases

所以我正在编写这段代码,我想通过使用循环获取数据库的数据来做到这一点。我遇到的问题是,我似乎找不到一种方法将值从我得到的按钮推送到数据库。我对想法持开放态度。谢谢!

<!Doctype HTML>
<html>
<head>
    <link rel="stylesheet" href="style.css" type="text/css"/>
    <title>Online Catalog</title>
</head>
<body>
<form action="" method="get">
<?php 
session_start();
require('database.php');
echo "<h1><a href=". 'index.php' .">Catalog</a></h1>
<b id=".cart."><a href=". 'cart.php' .">Show cart</a></b>";
if ($result = $connection->query("SELECT * FROM `store`")) {
    $row_cnt = $result->num_rows;
    while ($row = $result->fetch_assoc()) {
        echo "<p>
            <table>
                <th>
                    <img src=".$row[img_path].'/'.$row[img_name].">
                </th>
                <td>
                    <h2>". $row[name] ."</h2><br>
                    ". $row[description] ."<br><br>
                    Price : ". $row[price] ."$<br>
                </td>
                <td >
                    <input type='submit' name='add".$row[id]."' value='Add to cart'/>
                </td>
            </table>
        </p>
        ";
        if(isset($_GET['add.$row[id].'])){
            $cart=1;
            if(mysqli_query($connection, "INSERT INTO `store-project`.`store` (`incart`) VALUES ('$cart')")){
                mysqli_close($connection);
                header("Location: cart.php");
            }   
        }
    }

    $result->close();
}
?>
</form>
</body>
</html>

这是数据库

这是它通常的样子

尝试在表单中使用Post方法。

if($_POST['add.$row['id'].']){
$insert = "insert into store-project.store           
set incart = '".$cart1."';
mysqli_query($insert);
header("Location: cart.php");
}

希望对你有帮助