2012-04-23 4 views
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="">'; 
    } 

?> 

автомобиля информация (Укажите один автомобиль)

<?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> 
+0

Перед траление через все, что код, вы можете дать * любой * намекает, что это не так? Что вы ожидаете, что происходит на самом деле, какие ошибки вы получили ....... – Hamish

+0

@hamish В принципе, продукт не добавляет в корзину его просто остается на странице информации о тележке, когда я нажимаю кнопку add to тележка. – Tesh

ответ

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"">'; 

EDIT:

<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']){ 
..... 
+0

все еще имея такую ​​же проблему, к сожалению, вы имели в виду перед $ _SESSION ['cart'], чтобы добавить session_start() ;? – Tesh

+0

добавить 'session_start();' перед этим комментарием '// если продукт существует в командной строке, добавьте его в корзину' и удалите session_start() позже. Я отредактировал свой ответ с вашим кодом. – WolvDev

+0

Его все еще делает то же самое :(он остается на странице информации о машине и не идет на страницу с тележкой ... – Tesh

Смежные вопросы