gpt4 book ai didi

PHP 购物篮问题

转载 作者:行者123 更新时间:2023-11-29 13:27:15 25 4
gpt4 key购买 nike

我目前正在尝试在我的个人网站上实现购物篮功能,但似乎很困难。我已经从我的产品页面添加了链接,并且按照应有的方式传递了“ID”信息,但是每当我将产品添加到我的购物篮时,它会将我带到我的购物篮页面,它总是显示“您的购物篮中没有商品”购物篮'。这是我的脚本,如果对这个问题有任何帮助,我们将不胜感激。这是我的第一次尝试,我在这方面的 php 技能有限,考虑到这一点,如果有一个非常简单的解决方案,我深表歉意。

    <?php
if ($_Get[action]=="add") {
$radio_id=$_Get[radio_id];
$_Session[$radio_id]++;
}

if($_SESSION[$radio_id]) {
echo "<table border=\"1\" padding=\"3\" width=\"40%\">";

foreach($_SESSION[$radio_id] as $radio_id => $quantity) {

$result = mysqli_query($link, "SELECT * FROM radios WHERE radio_id=".$_GET[radio_id]) or die( mysqli_error($link));
$array = mysqli_fetch_array($result);

//echo "<p>Manufacturer: " . $array[manufacturer] . "<br>";
//echo "Model: " . $array[model] . "<br>";
//echo "Price: " . $array[price] . "<br>";
//echo "Description: " . $array[description] . "</p>";

if(mysql_num_rows($result) > 0) {

list($array[model], $array[manufacturer], $array[description], $array[price]) = mysql_fetch_row($result);

$line_cost = $array[price] * $quantity;
$total = $total + $line_cost;

echo "<tr>";
echo "<td align=\"center\">$name</td>";
echo "<td align=\"center\">$quantity <a href=\"$_SERVER[PHP_SELF]?action=remove&id=$product_id\">X</a></td>";
echo "<td align=\"center\">$line_cost</td>";
echo "</tr>";
}
}

echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total</td>";
echo "<td align=\"right\">$total</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"3\" align=\"right\"><a href=\"$_SERVER[PHP_SELF]?action=empty\" onclick=\"return confirm('Are you sure?');\">Empty Cart</a></td>";
echo "</tr>";
echo "</table>";
}

else{
echo "You have no items in your shopping cart.";
}
?>

最佳答案

需要纠正的几点:

  • $_Get 应为 $_GET
  • $_Session 应为 $_SESSION

由于 session 语法不正确,您面临此问题。在第四行将 $_Session 更改为 $_SESSION。如果您尚未开始 session ,还可以在页面开头使用 session_start()

更新的代码:

<?php
session_start();
if ($_GET['action']=="add") {
$radio_id=$_GET['radio_id'];
$_SESSION[$radio_id]++;
}

关于PHP 购物篮问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19968142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com