944,048 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3763
  • PHP RSS
Feb 16th, 2006
0

Simple Shopping Cart with arrays

Expand Post »
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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nisrin is offline Offline
18 posts
since Jan 2006
Mar 4th, 2006
0

Re: Simple Shopping Cart with arrays

If you don't want to use PHP, perhaps you should not post this question in the PHP forum? Try the Javascript forum.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jun 11th, 2007
0

Re: Simple but working Shopping Cart with arrays

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Achiever is offline Offline
1 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: help with pregmatch
Next Thread in PHP Forum Timeline: my small prject





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC