Hi,
Im really new to php and stuff…But as my Final year project Im developing a shoppingcart system.But there is an error which I could not figure out …If you can plzz help me…There for anyone who logged it will display the same cart…I think problem is cz i hve set a cookie instead of a session…But Im unable to correct it…Here Im sending you my code plz correct it and help me…Im totally stucked with this issue…
shopcart.php
<?php session_start(); if(!isset($_SESSION['valid']) || $_SESSION['valid']!="yes") { header("location:index.php"); //print "invalid login"; exit(); } ?> <!-- function UpdateQty(item) { itemId = item.name; newQty = item.options[item.selectedIndex].text; document.location.href = 'shopcart.php?action=update_item&id='+itemId+'&qty='+newQty; } </script> <?php include_once "../connect.php"; //$myusername = $_SESSION['user_name']; if(isset($_GET["action"])) { switch($_GET["action"]) { case "add_item": { AddItem($_GET["id"], $_GET["qty"]); ShowCart(); break; } case "update_item": { UpdateItem($_GET["id"], $_GET["qty"]); ShowCart(); break; } case "remove_item": { RemoveItem($_GET["id"]); ShowCart(); break; } case "show_cart": { ShowCart(); } } } function AddItem($itemId, $qty) { $result = mysql_query("SELECT COUNT(*) FROM tbl_cart WHERE cookie_id = '" . GetCartId() . "' AND item_id =$itemId") or die(mysql_error()); $row = mysql_fetch_row($result); $numRows = $row[0]; if($numRows == 0) { // This item doesn't exist in the users cart,we will add it with an insert query mysql_query("INSERT INTO tbl_cart(cookie_id,item_id, qty) VALUES('" . GetCartId() . "', $itemId, $qty)") or die(mysql_error()); } else { // This item already exists in the users cart,we will update it instead UpdateItem($itemId, $qty); } } function UpdateItem($itemId, $qty) { mysql_query("UPDATE tbl_cart SET qty = $qty WHERE cookie_id = '" . GetCartId() . "' AND item_id = $itemId") or die(mysql_error()); } function RemoveItem($itemId) { mysql_query("DELETE FROM tbl_cart WHERE cookie_id = '" . GetCartId() . "' AND item_id = $itemId") or die(mysql_error()); } function ShowCart() { $result = mysql_query("SELECT * FROM tbl_cart INNER JOIN tbl_product ON tbl_cart.item_id = tbl_product.prod_id WHERE tbl_cart.cookie_id = '".GetCartId()."' ORDER BY tbl_product.prod_name ASC") or die(mysql_error()); //echo("