Simple Shopping Cart with arrays

Reply

Join Date: Jan 2006
Posts: 18
Reputation: nisrin is an unknown quantity at this point 
Solved Threads: 0
nisrin nisrin is offline Offline
Newbie Poster

Simple Shopping Cart with arrays

 
0
  #1
Feb 16th, 2006
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...
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Simple Shopping Cart with arrays

 
0
  #2
Mar 4th, 2006
If you don't want to use PHP, perhaps you should not post this question in the PHP forum? Try the Javascript forum.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1
Reputation: Achiever is an unknown quantity at this point 
Solved Threads: 0
Achiever Achiever is offline Offline
Newbie Poster

Re: Simple but working Shopping Cart with arrays

 
0
  #3
Jun 11th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC