1

誰かが私を助けることができるかどうか疑問に思っていました。商品がカートに追加されないという問題が発生しています。誰かが私を助けたり、私のコードの間違いを見つけたりできるかどうか疑問に思っていました.大量のコードについて申し訳ありませんが、助けてくれてありがとう..

車の価格 (データベースにあるすべての車を表示します)

<head>
<title>Car Prices</title>

<!--main.css stylesheet involves the positioning of the website and effects that have been applied to the website-->
<!--slider.css stylsheet involves the positioning the size and the time frame of the slideshow that have been created-->
<!--menu.css stylesheet involves the form of navigation and the styles that have been applied to that horizontal navigation bar-->

<link href="css/main2.css" rel="stylesheet" type="text/css" />
<link href="css/slider.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />


</head>

<body>

<span class = "title1">Prestige Supercars Car Price</span>

<div id = "header1">

<!-- as i wanted the button to be wrapped with the text on top i had to wrap the text over the button-->


<?php

require "dbc.php";

$query = "SELECT * from cars";

$result = mysql_query ($query);

$rCount = mysql_num_rows($result);

$aresult = array();

$aresult = mysql_fetch_array($result);

while($row = mysql_fetch_array($result)){

$CID = $row ["id"];

echo'<div id="content7">
     <div class="car-image"><a href="carinformation.php?id='.$row["id"]. '"><img width="500px" height="200px" src="data:image/jpeg;base64,'. base64_encode($row["picture"]). '" />';
echo '<div id="title2">'.$row ["Car_Name"];
echo '<br />Price: &pound'.$row ["Price"];
echo '</div>';
     '<input name="viewdetails" type="submit" value="More" onClick="">';
     }

?>  

車両情報(1台の車両を指定)

<?php

$carid = $_GET['id'];
require_once "dbc.php";

$result = mysql_query('SELECT * FROM cars WHERE id = "'.$carid.'"');
$rCount = mysql_num_rows($result);
?>
<?php
if($row = mysql_fetch_array($result)){
do{
     $CID = $row ["id"];
    echo '<div id="content8"><form name="userForm" method="post" action="cart.php?cid='.$row['id'].'">';
    echo '<div class="car-image"><a href="carinformation.php?id='.$row["id"]. '"><img width="500px" height="200px" src="data:image/jpeg;base64,'. base64_encode($row["picture"]). '" />';
    echo '<div id="title2">'.$row ["Car_Name"];
    echo '<br />Quantity: '.$row ["Quantity"];
    echo '<br />Price: &pound'.$row ["Price"];
    echo '<br/><input name="addCart" type="submit" value="ADD TO CART" onClick="">';

    echo '</form></div>';
    echo '<br/><br/><br/><br/><br/>';

    }while($row = mysql_fetch_array($result));
    }else{print"Sorry, no records where found!";}
?>
</body>
</html>

カート

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Presige Supercars -->

<head>
<title>Prestige Cars Cart</title>
</head>

<?php

//if product exists in command line, add it to cart
    @ $cid = $_GET['cid'];  
    //checks if command line has product added
    if($cid){
        //checks if cart is empty & creates it
        if(!isset($_SESSION['cart'])){
            $_SESSION['cart'] = array();
            $_SESSION['items'] = 0;
            $_SESSION['total_price'] = '0.00';
        }
        //cart array contains car id & quantity
        if (isset($_SESSION['cart'] [$cid] ))
            $_SESSION['cart'] [$cid]++;
        else 
            $_SESSION['cart'] [$cid] = 1;
    }

    //checks if command line has product updated
    if(isset($_POST['update'])){   
        foreach ($_SESSION['cart'] as $carid => $qty){
            //value from text box name
            if($_POST[$carid]<='0')
                unset($_SESSION['cart'] [$carid]);
            else 
                $_SESSION['cart'] [$carid] = $_POST[$carid];
        }
    }
?>

<?php
session_start();
?>
<?php
    //displays car
    if  ($_SESSION['cart']){
        //echo '<h3>Cart Contents</h3>';
        echo '<div id="content7">';
        echo '<table width="600" border="0" cellpadding=1 cellspacing=3>';
        echo '<form name="userForm" method="post" action="cart.php">';
        echo '<tr><th width="300" scope="col" align="center">Title</th>';
        echo '<th width="100" align="right">Quantity</th>';
        echo '<th width="150" align="right">Price</th></tr>';
        $_SESSION['total_price'] = '0.00';
        $_SESSION['items'] = 0;

        //place lines of products in page
            foreach ($_SESSION['cart'] as $carid => $qty){
            //Connect to your Database Server with your credentials
            require "dbc.php";

            $query = 'SELECT * FROM cars WHERE id = "'.$carid.'"';
            $result = mysql_query($query);
            $catNo = mysql_num_rows($result);
            $aresult = array();

            $product = mysql_fetch_array($result);
            $tprice = $qty*$product['Price'];
            echo '<tr><td align = "left"><span>';
            echo $product['Car_Name'];
            echo '</span></td>';
            echo '<td align = "right"><span>';
            //name of textbox=carid and value=qty
            echo '<input name="'.$carid.'" type="text" size="3" maxlength="3" value="'.$qty.'">';
            echo '</span></td>';
            echo '<td align = "right"><span>&pound;';
            echo $tprice;
            echo '</span></td></tr>';

            $_SESSION['items'] += $qty;
            $_SESSION['total_price'] += $tprice;

            //close the connection
            mysql_close($conn);
        }
        echo '<input type="hidden" name="update" value=true>';
        echo '<tr bgcolor="yellow"><td align="center">';
        echo '<input type="submit" name="Submit" value="Update Cart"></td>';
        echo '<td align = "right"><b>Total Qty: '.$_SESSION['items'].'</b></td>';
        echo '<td align="right"><b>Total: &pound;'.$_SESSION['total_price'].'</b></td>';
        echo '</tr>';
        echo '</table>';
        echo '</form>';
        echo '<br/><br/>';
        echo '<form action="pay.php" method="post">';
        echo '<input type="submit"  name="CHECKOUT" value="CHECKOUT"></form>';

        //echo '</div>';

    }else{  //if no product in cart
        echo '<div id="content7">';
        echo '<h3><span>You currently have no products in Shopping Cart.</span></h3>';
        echo '<p class="p1"><span></span></p>';
        //echo '</div>';
    }
    ?>
</body>
</html>
4

1 に答える 1

1

cart.php で が存在するかどうかを尋ねますが、数行後に$_SESSION['cart']呼び出します。「カートに入れる」機能の前に書いてsession_start()ください。session_start();

EDIT2:

//CHANGE action and method attribute
    echo '<div id="content8"><form name="userForm'.$row["id"].'" method="get" action="cart.php">';
    echo '<div class="car-image"><a href="carinformation.php?id='.$row["id"]. '"><img width="500px" height="200px" src="data:image/jpeg;base64,'. base64_encode($row["picture"]). '" />'; 
    echo '<div id="title2">'.$row ["Car_Name"]; 
    echo '<br />Quantity: '.$row ["Quantity"]; 
    echo '<br />Price: &pound'.$row ["Price"];
//CHANGE add this line --v
    echo '<input type="hidden" name="cid" value="'.$row['id'].'" />';
    echo '<br/><input name="addCart" type="submit" value="ADD TO CART"">'; 

編集:

<head> 
<title>Prestige Cars Cart</title> 
</head> 

<?php 

//==========================ADD SESSION_START() HERE==========================
session_start();

//if product exists in command line, add it to cart 
    @ $cid = $_GET['cid'];   
    //checks if command line has product added 
    if($cid){ 
        //checks if cart is empty & creates it 
        if(!isset($_SESSION['cart'])){ 
            $_SESSION['cart'] = array(); 
            $_SESSION['items'] = 0; 
            $_SESSION['total_price'] = '0.00'; 
        } 
        //cart array contains car id & quantity 
        if (isset($_SESSION['cart'] [$cid] )) 
            $_SESSION['cart'] [$cid]++; 
        else  
            $_SESSION['cart'] [$cid] = 1; 
    } 

    //checks if command line has product updated 
    if(isset($_POST['update'])){    
        foreach ($_SESSION['cart'] as $carid => $qty){ 
            //value from text box name 
            if($_POST[$carid]<='0') 
                unset($_SESSION['cart'] [$carid]); 
            else  
                $_SESSION['cart'] [$carid] = $_POST[$carid]; 
        } 
    } 
?> 

<?php 
//==========================REMOVE SESSION_START() HERE==========================
?> 

<?php 
    //displays car 
    if  ($_SESSION['cart']){ 
.....
于 2012-04-23T11:28:28.753 に答える