I am making a shopping cart using javascript and php.I have a problem ....when i have already added a item to shopping cart basket and want to add a new products in the basket...the product which was previously added is not shown in the basket..
how to came out this problem..???
I am using cookie functions to store the values for the item selected to add in the basket...but not getting the right output..
here is the functions for cookies ..which i am using..(i want to store id, name,quantity,price and expiry date of products in cookie..
Code: Select all
function createCookie(id,name,qt,price,days)
{
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = id+name+qt+price+expires+"; path=/";
}
function getCookie(id,name,qt,price) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function delCookie(name) {
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
} And here is the page where i want to fetch the values which are added in the basket previously.
Code: Select all
<?php
$price= $_GET['price']; //i am getting these values through url (using window.location)any other method to send these values???
$code= $_GET['code'];
$name= $_GET['name'];
$qt= $_GET['qt'];
echo"<table border ='7' cellpadding='10' cellspacing = '10' bgcolor='pink'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Quantity</th>
<th>Price</th>
<tr>";
echo"<tr>";
echo"<td>" . $code . "</td>";
echo"<td>" . $name . "</td>";
echo"<td>";
?>
<form action="" method="post">
<input type="text" name="qt" value="<?php echo $qt ?>" size="2" >
</form>
<?php
echo"</td>";
echo"<td>" . $price . "</td>";
?>
<script type="text/javascript" src="translate.js"></script>
<script language="javascript">
createCookie("name","<?php echo $name ?>"); //here i m getting only current value for $name.
var x = document.cookie;
document.write(x);
</script>Any suggetion regarding this.???
Thanks
regards
amit