我想添加"添加到购物车"已经设计好的网站中的选项,在产品页面中,通过从mysql表中获取数据来显示产品,我有多个产品,为此我想添加一个"添加到购物车"只要用户点击"添加到购物车"链接,它应该只添加当前查看产品的用户到另一个新的mysql表而不是所有产品都来自mysql产品表,我有一个参考代码
http://www.sanwebe.com/2013/06/creating-simple-shopping-cart-with-php/comment-page-2
https://www.codeofaninja.com/2013/04/shopping-cart-in-php.html
在给定的参考链接中,产品在表格中指定,每个产品都有一个"添加到购物车"选项可用,但对我来说,我想要单个"添加到购物车"多个号码产品页面的选项,请帮我找到参考代码的人
我是php和mysql的新手,所以我尝试了自己的逻辑,我希望用户获取当前查看产品,数据应该添加到数据库中的新表中,我将显示新表作为查看购物车
1)我不知道当用户点击“#34;添加到购物车”时如何获取当前查看产品。链路
2)下面的代码显示了来自td_excel表的数据,但未将其更新到产品表
<?php
session_start();
$servername = "";
$username = "";
$password = "";
$dbname = "php_automobile";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
/* $_SESSION['$auto_name'] = $automobil_name;
$_SESSION['$auto_price'] = $pric; */
$sqls = "SELECT id, Vehicle_description, Wholesale FROM td_excel";
$results = mysqli_query($conn, $sqls);
if (mysqli_num_rows($results) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($results)) {
echo "id: " . $row["id"]. " - Name: " . $row["Vehicle_description"]. " -Price:." .$row["Wholesale"]. "
<br>";
$automobil_name = $_GET['Vehicle_decription'];
$price = $_GET['Wholesale'] ;
}
} else {
echo "0 results";
}
$sql = "INSERT INTO products ".
"(`automobile_name`,`price`) ".
"VALUES ".
"('$automobil_name','$pric')";
if (mysqli_query($conn, $sql)) {
echo "Added to cart successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>