购物车500错误我缺少什么?

时间:2017-05-11 04:15:52

标签: php html mysql shopping-cart

我有一个关于我正在建立的购物车的问题,当我将表单提交到购物车时,我收到500错误,因此系统根本不会在购物车上抓住我的商品。知道如何解决这个问题吗?这是代码,在此先感谢您的帮助。

index.php文件

<?php   
session_start();  
$connect = mysqli_connect("localhost", "root", "12345", "shopping");  
if(isset($_POST["add_to_cart"]))  
{  
if(isset($_SESSION["shopping_cart"]))  
{  
$item_array_id = array_column($_SESSION["shopping_cart"], "item_id");  
if(!in_array($_GET["id"], $item_array_id))  
{  
$count = count($_SESSION["shopping_cart"]);  
$item_array = array(  
'item_id'               =>     $_GET["id"],  
'item_name'               =>     $_POST["hidden_name"],  
'item_price'          =>     $_POST["hidden_price"],  
'item_quantity'          =>     $_POST["quantity"]  
);  
$_SESSION["shopping_cart"][$count] = $item_array;  
echo '<script>window.location="cart.php"</script>';
}  
else  
{   
echo '<script>window.location="cart.php"</script>';  
}  
}  
else  
{  
$item_array = array(  
'item_id'               =>     $_GET["id"],  
'item_name'               =>     $_POST["hidden_name"],  
'item_price'          =>     $_POST["hidden_price"],  
'item_quantity'          =>     $_POST["quantity"]  
);  
$_SESSION["shopping_cart"][0] = $item_array;  
}  
}  
if(isset($_GET["action"]))  
{  
if($_GET["action"] == "delete")  
{  
foreach($_SESSION["shopping_cart"] as $keys => $values)  
{  
if($values["item_id"] == $_GET["id"])  
{  
unset($_SESSION["shopping_cart"][$keys]);   
echo '<script>window.location="cart.php"</script>';  
}  
}  
}  
}  
?>

现在这是我的表格后期行动:

action="index.php?action=add&id=<?php echo $row["id"]; ?>"

card.php文件

<?php   
 session_start();  
 $connect = mysqli_connect("localhost", "root", "12345", "shopping"); 
 if(isset($_POST["add_to_cart"]))  
 {  
      if(isset($_SESSION["shopping_cart"]))  
      {  
           $item_array_id = array_column($_SESSION["shopping_cart"], "item_id");  
           if(!in_array($_GET["id"], $item_array_id))  
           {  
                $count = count($_SESSION["shopping_cart"]);  
                $item_array = array(  
                     'item_id'               =>     $_GET["id"],  
                     'item_name'               =>     $_POST["hidden_name"],  
                     'item_price'          =>     $_POST["hidden_price"],  
                     'item_quantity'          =>     $_POST["quantity"]  
                );  
                $_SESSION["shopping_cart"][$count] = $item_array;  
           }  
           else  
           {    
                echo '<script>window.location="cart.php"</script>';  
           }  
      }  
      else  
      {  
           $item_array = array(  
                'item_id'               =>     $_GET["id"],  
                'item_name'               =>     $_POST["hidden_name"],  
                'item_price'          =>     $_POST["hidden_price"],  
                'item_quantity'          =>     $_POST["quantity"]  
           );  
           $_SESSION["shopping_cart"][0] = $item_array;  
      }  
 }  
 if(isset($_GET["action"]))  
 {  
      if($_GET["action"] == "delete")  
      {  
           foreach($_SESSION["shopping_cart"] as $keys => $values)  
           {  
                if($values["item_id"] == $_GET["id"])  
                {  
                     unset($_SESSION["shopping_cart"][$keys]);  
                     echo '<script>window.location="cart.php"</script>';  
                }  
           }  
      }  
 }  
 ?>

现在,当我提交时,我在页面上收到500错误,浏览器会在我的域名上显示此链接:http://localhost/shops/index.php?action=add&id=1。知道如何解决这个问题吗?我根本没有任何线索。 :(

0 个答案:

没有答案