| | |
Simple Shopping Cart with arrays
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2006
Posts: 18
Reputation:
Solved Threads: 0
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>
Product Name
</th>
<th>
Quantity Ordered
</th>
<th>
Product Price
</th>
<th>
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>
Total Cost in Shopping Cart
</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...
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>
Product Name
</th>
<th>
Quantity Ordered
</th>
<th>
Product Price
</th>
<th>
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>
Total Cost in Shopping Cart
</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...
If you don't want to use PHP, perhaps you should not post this question in the PHP forum? Try the Javascript forum.
•
•
Join Date: Jun 2007
Posts: 1
Reputation:
Solved Threads: 0
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.
![]() |
Similar Threads
- which is the best technology to make online shopping cart? (IT Professionals' Lounge)
- Shopping Cart Not Working (ASP.NET)
- CAn anyone provide me a very simple code for shopping cart? (PHP)
- shopping cart using jsp, servlet, javabean (Community Introductions)
- ISO hosted great shopping cart with other features (eCommerce)
- Shopping cart class (Java)
- dell.com shopping cart save feature (Database Design)
Other Threads in the PHP Forum
- Previous Thread: help with pregmatch
- Next Thread: my small prject
| Thread Tools | Search this Thread |
.htaccess access alexa apache api array beginner binary broken cakephp checkbox class cms code convert cron curl database date directory display dropdown dynamic echo email encode error fairness file files folder form forms function functions google hack href htaccess html image include indentedsubcategory insert ip javascript joomla limit link login loop mail mail() menu methods mlm multiple multipletables mysql network newsletters oop passwords paypal pdf php problem provider query radio random recursion redirect remote script search secure securephp server sessions simple sms source space sql syntax system table tutorial update upload url user validator variable variables video voteup web youtube





