PHP索引.php,添加到购物车问题


php index.php, add to cart issue

我在索引中执行此代码时遇到问题.php。

它说"购物车操作未设置"

我需要你的帮助 php 大师。我可以显示修复此错误所需的任何文件。

这是代码:

// Handle AJAX requests
if (isset ($_GET['AjaxRequest']))
{
// Headers are sent to prevent browsers from caching
header('Expires: Fri, 25 Dec 1980 00:00:00 GMT'); // Time in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/html');
  if (isset ($_GET['CartAction']))
  {
    $cart_action = $_GET['CartAction'];
    if ($cart_action == ADD_PRODUCT)
    {
      require_once 'C:/vhosts/phpcs5/presentation/' . 'cart_details.php';
      $cart_details = new CartDetails();
      $cart_details->init();
      $application->display('cart_summary.tpl');
    }
    else
    {
      $application->display('cart_details.tpl');
    }
  }
  else
    trigger_error('CartAction not set', E_USER_ERROR);
}
else
{
  // Display the page
  $application->display('store_front.tpl');
} 

这是因为您的代码在 url 中需要一个名为"CartAction"的参数

例:

www.yoursite.com/?CartAction=ADD_PRODUCT

GET 方法发送附加到页面请求的编码用户信息。页面和编码信息由 ?字符。源

您检查if $_GET['CartAction']有一个值(从上面的 url 中,这个超全局变量的值为"ADD_PRODUCT")

@Mackiee(

在注释中)和错误消息都告诉您的是,问题是缺少查询参数。调用此 this 的 URL 需要包含 ?CartAction=ADD_PRODUCT&CartAction=ADD_PRODUCT