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

PHP在线商店、循环按钮和;数据库,php,shopping-cart,Php,Shopping Cart,所以我在写这段代码,我想通过使用循环获取数据库的数据来实现它。我遇到的问题是,我似乎找不到一种方法从我得到的按钮将值推送到数据库。我乐于接受各种想法。谢谢 <!Doctype HTML> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"/> <title>Online Catalog</title> </head&

所以我在写这段代码,我想通过使用循环获取数据库的数据来实现它。我遇到的问题是,我似乎找不到一种方法从我得到的按钮将值推送到数据库。我乐于接受各种想法。谢谢

<!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");
}

希望对您有所帮助

你好,Boian,欢迎来到Stack Overflow。我很抱歉,但你问的问题完全不清楚。请参阅教程页面和帮助中心,了解如何提出好的问题。谢谢您。