hi

Ive created a simple shopping cart using arrays and a cookie. The cookie is used to store the number of orders that have been made yet, extracting that value from the cookie and using it in a loop should display all the products quantity, price and total cost...BUT THAT DOESNT WORK, it just keeps getting overwritten. Heres the code:

<?php

$Itempointer=0;

//if the cookie exists
if(isset($_COOKIE['NumberOrdered']))
{
    $ItemPointer = $_COOKIE['NumberOrdered']
    echo "Cookie exists!";
}
else
{
    setcookie('NumberOrdered','1',time()+2592000,'/','127.0.0.1');
    echo "Cookie DOES NOT exist!";
}

$Itempointer++;

//shopping baskets for arrays of name, qty,
//price and cost. A variable for total cost.
$basket_tcost = "";
$basket_name[10] = "";;
$basket_quantity[10] = "";;
$basket_price[10] = "";;
$basket_cost[10] = "";;

//getting the items from the web page.
$basket_name[$Itempointer]=$_POST["id"];
$basket_quantity[$Itempointer]=$_POST["quantity"];
$basket_price[$Itempointer]=$_POST["price"];
$basket_cost[$Itempointer]= $_POST["quantity"] * $_POST["price"];
$basket_tcost+= $basket_cost[$Itempointer];


?>
<html>
<head>
    <title>Order Page</title>
    <link rel="stylesheet" type="text/css" href="../../../mystyle.css"/>
</head>
<body>
<h1>Order Page</h1>
<p>
<div align="center">
<table bordercolor="#C0C0C0" style="border-collapse: collapse; color:#CCCCFF ;font-family:'Palatino Linotype'" cellpadding="8" cellspacing="1" border="5" width="0" >
  <tr>
     <th>
         &nbsp; Product Name
      </th>
     <th>
        &nbsp; Quantity Ordered
      </th>
      <th>
    &nbsp; Product Price
      </th>
      <th>
    &nbsp; Total Cost
      </th>      
  </tr>

<?php
for($i=1; $i<=$Itempointer; $i++)
{
    echo "<tr>
            <td>
        $basket_name[$i]
            </td>
            <td>
        $basket_quantity[$i]
            </td>
            <td>
        $basket_price[$i]
            </td>
            <td>
        $basket_cost[$i]
            </td>
    </tr>";
}
?>

  <tr>
     <th colspan = 3>
        &nbsp; Total Cost in Shopping Cart &nbsp;
      </th>
      <td>
    <?php echo $basket_tcost; ?>
      </td>  
  </tr>
</table>
</div>
</p>
</body>
</html>

Please help me out here....I dont want to use php with mySql....i just want to use something simple...Thanks so much...

Edited 3 Years Ago by happygeek: fixed formatting

If you don't want to use PHP, perhaps you should not post this question in the PHP forum? Try the Javascript forum.

I am new to DaniWeb and i don't seem to find a way of posting my question so i have just taken advantage of a similar question. I need the code for creating a shopping cart and a log book in php but i need one which will work. I have developed a website for an IT firm where i work, and i need to add a shopping cart and a log book but i am stuck. How do i go about it together with mysql? Please help.

This article has been dead for over six months. Start a new discussion instead.