2013-04-13 3 views
0

장바구니 페이지를 코딩했는데 아무 것도 표시하지 않는 것 같습니다. 이전에는 제품 페이지에 양식 추가 기능이있어서 장바구니에 추가를 클릭하면 cart.php로 연결됩니다. 나는 여기서 무엇이 잘못되었는지 확신하지 못한다.장바구니 페이지에 아무 것도 표시되지 않습니다.

<?php 
session_start(); 
//script error reporting 
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 
// Connect to the MySQL database 
include "storescripts/connect.php"; 
?> 

<?php 
if (isset($_POST['pid'])) { 
$pid = $_POST['pid']; 
$wasFound = false; 
$i = 0; 
// if the cart session variable is not set or cart array is empty 
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { 
    // run if the cart is empty or not set 
    $_SESSION["cart_array"] = array(1 => array("item_id" => $pid, "quantity" => 1)); 
} else { 
    // run if the cart has at least one item in it 
    foreach ($_SESSION["cart_array"] as $each_item) { 
     $i++; 
     while (list($key, $value) = each($each_item)) { 
      if ($key == "item_id" && $value == $pid) { 
       //that item is in cart already so let's adjust its quantity using array_slice() 
       array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1))); 
       $wasFound = true; 
      } //close if condition 
     }//close while loop 
    }//close foreach loop 
    if ($wasFound == false) { 
     array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1)); 
    } 
    } 
} 
?> 
<?php 
// SECTION 2(if user chooses to empty their shopping cart) 
if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") { 
unset($_SESSION["cart_array"]); 
} 
?> 
<?php 
// SECTION 3 (render the cart for the user to view) 
$cartOutput = ""; 
if (!isset($_SESSION["crt_array"]) || count($_SESSION["cart_array"]) < 1) { 
$cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>"; 
} else { 
$i = 0; 
foreach ($_SESSION["cart_array"] as $each_item) { 
    $i++; 
    $item_id = $each_item["item_id"]; 
    $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); 
    while ($row = mysql_fetch_array($sql)) { 
     $product_name = $row["product_name"]; 
     $price = $row["price"]; 
    } 
    $cartOutput .= "<h2>Cart Item $i</h2>"; 
    //while(list($key, $value) = each($each_item)) 
      // $cartOutput .= "$key: $value<br/>"; 
    $cartOutput .= "Item ID:" . $each_item['item_id'] . "<br/>"; 
    $cartOutput .= "Item Quantity:" . $each_item['quantity'] . "<br/>"; 
    $cartOutput .= "Item Name:" . $product_name . "<br/>"; 
    $cartOutput .= "Item Price: $" . $price . "<br/>"; 
    } 
} 
?> 
+0

해결되었습니다! 시간을내어 주셔서 감사합니다.) 투표를하지 마십시오.이 사이트는 큰 도움이되며, 다른 분야의 다른 사람들을 도울 수 있기를 바랍니다. 고마워 (: – nur

+0

도움이된다면 대답을 받아들이지 말라.) – 1337holiday

답변

0

여기에 사소한 오류가 있습니다. 내 철자 실수. 그것은 일어난다. 인간의 실수는 항상 발생합니다 (: 그리고 세션 카트 배열 (:

+0

감사합니다! – nur

관련 문제