【发布时间】:2016-02-06 01:19:03
【问题描述】:
所以我正在编写这段代码,我想通过使用循环获取数据库的数据来实现它。我遇到的问题是我似乎无法找到一种方法将值从我得到的按钮推送到数据库。我对想法持开放态度。谢谢!
<!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>
【问题讨论】:
-
您好,Boian,欢迎来到 Stack Overflow。对不起,但绝对不清楚你在问什么。请查看导览页面并查看帮助中心,了解如何提出好的问题。谢谢。
标签: php shopping-cart