Ask a Question related to Dreamweaver AppDev, Design and Development.
-
urbanactive #1
Php Shopping Cart
If anybody can help that would be great. ok here's my problem, i have a PHP
shopping cart that i have built in dreamweaver mx 2004 . i have a products page
that pulls the products in from a Mysql database just fine.then the customer
chooses a size and them clicks add to cart, it goes to the shopping cart, BUT
nothing shows up. below is the code for my products page and my cart pages. :(
please somebody help me im really in need of some help. thanks in advance
Mike
Products .php
<?php require_once('Connections/ConnHeismy.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
session_start();
session_set_cookie_params(0);
?>
<?php
$maxRows_rsProducts = 10;
$pageNum_rsProducts = 0;
if (isset($_GET['pageNum_rsProducts'])) {
$pageNum_rsProducts = $_GET['pageNum_rsProducts'];
}
$startRow_rsProducts = $pageNum_rsProducts * $maxRows_rsProducts;
mysql_select_db($database_ConnHeismy, $ConnHeismy);
$query_rsProducts = "select description, price, image, product_id , color from
products";
$query_limit_rsProducts = sprintf("%s LIMIT %d, %d", $query_rsProducts,
$startRow_rsProducts, $maxRows_rsProducts);
$rsProducts = mysql_query($query_limit_rsProducts, $ConnHeismy) or
die(mysql_error());
$row_rsProducts = mysql_fetch_assoc($rsProducts);
$productid=$row['product_id'];
$color=$row['color'];
if (isset($_GET['totalRows_rsProducts'])) {
$totalRows_rsProducts = $_GET['totalRows_rsProducts'];
} else {
$all_rsProducts = mysql_query($query_rsProducts);
$totalRows_rsProducts = mysql_num_rows($all_rsProducts);
}
$totalPages_rsProducts = ceil($totalRows_rsProducts/$maxRows_rsProducts)-1;
$queryString_rsProducts = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsProducts") == false &&
stristr($param, "totalRows_rsProducts") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsProducts = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsProducts = sprintf("&totalRows_rsProducts=%d%s",
$totalRows_rsProducts, $queryString_rsProducts);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="75%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="8%"> </td>
<td width="54%" bgcolor="#993300">Description</td>
<td width="5%" bgcolor="#993300">Price</td>
<td width="33%" bgcolor="#993300">Choose Size/Add To Cart </td>
</tr>
<?php do { ?>
<tr>
<td> </td>
<td><?php echo $row_rsProducts['description']; ?></td>
<td>$<?php echo $row_rsProducts['price']; ?></td>
<td><form action="cart.php?action=add_item&itemid=<?php echo "$productid"
?>&color=<?php echo "$color"?>" method="post" name="size" target="_self">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><input type="radio" name="size" value="Small" />
S
<input type="radio" name="size" value="Medium" />
M
<input type="radio" name="size" value="Large" />
L
<input type="radio" name="size" value="Xtra Large" />
XL
<input type="radio" name="size" value="Double XL" />
2XL</td>
</tr>
<tr>
<td width="64%"><input name="hiddenField" type="hidden"
value="<?php echo $row_rsProducts['$color']; ?>">
<input type="hidden" value="<?php echo
$row_rsProducts['$product_id']; ?>"></td>
<td width="36%"><input type="submit" name="Submit" value="Add To
Cart" /></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td> </td>
<td colspan="3"><hr /></td>
</tr>
<?php } while ($row_rsProducts = mysql_fetch_assoc($rsProducts)); ?>
</table>
<table width="76%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="77%"> </td>
<td width="23%" align="right"><table width="77%" border="0"
cellspacing="1" cellpadding="1">
<tr>
<td width="48%" align="right"><?php if ($pageNum_rsProducts > 0) { //
Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsProducts=%d%s", $currentPage,
max(0, $pageNum_rsProducts - 1), $queryString_rsProducts); ?>">Previous</a>
<?php } // Show if not first page ?></td>
<td width="52%" align="right"><?php if ($pageNum_rsProducts <
$totalPages_rsProducts) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsProducts=%d%s", $currentPage,
min($totalPages_rsProducts, $pageNum_rsProducts + 1), $queryString_rsProducts);
?>">Next</a>
<?php } // Show if not last page ?></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
</body>
</html>
<?php
mysql_free_result($rsProducts);
?>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------
Cart.php code
<?
$dbServer = "localhost";
$dbUser = "";
$dbPass = "";
$dbName = "store";
mysql_connect($dbServer, $dbUser, $dbPass);
mysql_select_db($dbName);
session_start();
session_set_cookie_params(0);
$sessionid = $PHPSESSID;
?>
<?php
switch($action)
{
case "add_item":
if(!isset($qty)){
$qty=1;
}
AddItem($itemid,$sessionid,$qty,$size,$color);
global $sessionid;
include ("./show_cart.php");
break;
case "remove_item":
RemoveItem($itemid,$sessionid,$size,$color);
include ("./show_cart.php");
break;
case "check_out":
include ("./checkout.inc");
break;
case "update_item":
$sql = "UPDATE cart SET qty = '$qty' WHERE itemid='$itemid' AND
size='$size' AND color='$color'";
if(!(mysql_query($sql))){
echo mysql_error();
die();
}
include ("./show_cart.php");
break;
default:
include ("./show_cart.php");
}
function AddItem($item,$sessionid,$qty,$size,$color){
global $sessionid ;
$session = $sessionid;
if(!check_if_in_cart($item,$size,$color,$session)) {
echo 'already in cart <a href="cart.php">Click Here</a> To view your
cart and increase quantity';
die();
}
$sql = 'INSERT INTO cart
(sessionid,itemid,qty,size,color)VALUES("'.$sessio n.'","'.$item.'","'.$qty.'","'
..$size.'","'.$color.'")';
if(!(mysql_query($sql))){
echo mysql_error();
die();
}
}
function RemoveItem($eyetem,$sessionid,$size,$color){
$sql = "DELETE FROM cart WHERE itemid='$eyetem' AND size='$size'AND
color='$color' AND sessionid='$sessionid'";
mysql_query($sql);
}
function check_if_in_cart($item,$size,$color,$session){
$sql="SELECT qty FROM cart WHERE sessionid='$session' AND itemid='$item' AND
size='$size'AND color='$color'";
if(!($result = mysql_query($sql))){
echo mysql_error();
die();
}
$numrows = mysql_num_rows($result);
if($numrows > 0){
return false;
}else{
return true;
}
}
?>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
----
Show_cart.php
<?
$bla="SELECT * FROM cart WHERE sessionid='$sessionid'";
if(!($result = mysql_query($bla))){
echo mysql_error();
die();
}
//number of items in cart
$numitems = mysql_num_rows($result);
//now to print information. Edit this information as needed
?>
<html>
<head>
<title>
::: He Is My ::: Global Ministries
</title>
<style type="type/css">
p{font-family: arial}
a {text-decoration: none}
</style>
</head>
<body>
<center>
<h3>Your Cart Contains:
<?=$numitems?>
Item(s)</h3>
<br>
<table border=0 cellpadding=2 cellspacing=2>
<tr>
<td width="72" bgcolor="#993300"><div align="center">Description</div></td>
<td width="35" bgcolor="#993300"><div align="center">Color</div></td>
<td width="25" bgcolor="#993300"><div align="center">Size</div></td>
<td width="51" bgcolor="#993300"><div align="center">Quantity</div></td>
<td width="88" bgcolor="#993300"><div
align="center">Update/Delete</div></td>
<td width="31" bgcolor="#993300"><div align="center">Price</div></td>
</tr>
<?php
while($row = mysql_fetch_array($result)){
$iid = $row["itemid"];
$result2 = mysql_query("SELECT * FROM products WHERE product_id =
\"$iid\"");
while ($row2 = mysql_fetch_array($result2)){
$totalamount = $totalamount + ($row["qty"] * $row2["price"]);
$totalamount = FormatCurrency($totalamount);
?>
<form method="post"
action="Original%20PHP%20FIles/cart.php?action=update_item&PHPSESSID=<?=$PHPSESS
ID?>">
<tr>
<td><?=$row2["description"]?></td>
<td><?=$row["color"]?></td>
<td><?=$row["size"]?></td>
<td><input type="text" size=2 name="qty" value="<?=$row["qty"]?>"><input
type="hidden" name="itemid" value="<?=$row["itemid"]?>"><input type="hidden"
name="size" value="<?=$row["size"]?>"><input type="hidden" name="color"
value="<?=$row["color"]?>"></td>
<td><font size="2">
<input type="submit" value="Update">
<a
href="Original%20PHP%20FIles/cart.php?action=remove_item&itemid=<?=$row["itemid"
]?>&size=<?=$row["size"]?>&color=<?=$row["color"]?>">Delete
Item From Shopping Cart</a></font></td>
<td>
<?php
echo FormatCurrency($row2["price"]);
?>
</td>
</tr>
</form>
<?ph
urbanactive Guest
-
shopping cart
Hi i would like to know. In CD-rom , it's possible to make a shopping cart I'm working on a site that requiers a shopping cart (just to calculate... -
CF Shopping Cart
Hi, I've a Shopping Cart Built in Coldfusion, can any body pls.let me know the Process of Processing My Order(shopping cart items) at... -
Shopping cart help
Hi, I need to create a shopping cart style website. Are there any good tutorials or 'shareware' stuff out there that I can look at? I want to do... -
shopping cart shopping
Im looking to buy some ecommerce software to hook up to an HTML site. The company will have around 350 products or so to start out, and will be... -
JS shopping cart
peterct07@yahoo.com (Peter Cartwright) wrote in message news:<b6141bd7.0307171525.1c322082@posting.google.com>... Oops wrong forum -
twocans #2
Re: Php Shopping Cart
How do you mean "But nothing shows up", can you explain more clearly. also
when the customer clicks on the add to cart button what are you passing and
how are you filtering.
[url]http://www.interaktonline.com[/url] have a good php cart
regards
twocans
"urbanactive" <webforumsuser@macromedia.com> wrote in message
news:d2vcqc$r4v$1@forums.macromedia.com...> If anybody can help that would be great. ok here's my problem, i have a
> PHP
> shopping cart that i have built in dreamweaver mx 2004 . i have a products
> page
> that pulls the products in from a Mysql database just fine.then the
> customer
> chooses a size and them clicks add to cart, it goes to the shopping cart,
> BUT
> nothing shows up. below is the code for my products page and my cart
> pages. :(
> please somebody help me im really in need of some help. thanks in advance
>
> Mike
>
> Products .php
>
>
>
>
>
>
> <?php require_once('Connections/ConnHeismy.php'); ?>
> <?php
> $currentPage = $_SERVER["PHP_SELF"];
>
> session_start();
> session_set_cookie_params(0);
>
> ?>
> <?php
> $maxRows_rsProducts = 10;
> $pageNum_rsProducts = 0;
> if (isset($_GET['pageNum_rsProducts'])) {
> $pageNum_rsProducts = $_GET['pageNum_rsProducts'];
> }
> $startRow_rsProducts = $pageNum_rsProducts * $maxRows_rsProducts;
>
> mysql_select_db($database_ConnHeismy, $ConnHeismy);
> $query_rsProducts = "select description, price, image, product_id , color
> from
> products";
> $query_limit_rsProducts = sprintf("%s LIMIT %d, %d", $query_rsProducts,
> $startRow_rsProducts, $maxRows_rsProducts);
> $rsProducts = mysql_query($query_limit_rsProducts, $ConnHeismy) or
> die(mysql_error());
> $row_rsProducts = mysql_fetch_assoc($rsProducts);
> $productid=$row['product_id'];
> $color=$row['color'];
> if (isset($_GET['totalRows_rsProducts'])) {
> $totalRows_rsProducts = $_GET['totalRows_rsProducts'];
> } else {
> $all_rsProducts = mysql_query($query_rsProducts);
> $totalRows_rsProducts = mysql_num_rows($all_rsProducts);
> }
>
> $totalPages_rsProducts =
> ceil($totalRows_rsProducts/$maxRows_rsProducts)-1;
>
> $queryString_rsProducts = "";
> if (!empty($_SERVER['QUERY_STRING'])) {
> $params = explode("&", $_SERVER['QUERY_STRING']);
> $newParams = array();
> foreach ($params as $param) {
> if (stristr($param, "pageNum_rsProducts") == false &&
> stristr($param, "totalRows_rsProducts") == false) {
> array_push($newParams, $param);
> }
> }
> if (count($newParams) != 0) {
> $queryString_rsProducts = "&" . htmlentities(implode("&",
> $newParams));
> }
> }
> $queryString_rsProducts = sprintf("&totalRows_rsProducts=%d%s",
> $totalRows_rsProducts, $queryString_rsProducts);
>
>
>
> ?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
> <title>Untitled Document</title>
> </head>
>
> <body>
> <table width="75%" border="0" cellspacing="2" cellpadding="2">
> <tr>
> <td width="8%"> </td>
> <td width="54%" bgcolor="#993300">Description</td>
> <td width="5%" bgcolor="#993300">Price</td>
> <td width="33%" bgcolor="#993300">Choose Size/Add To Cart </td>
> </tr>
> <?php do { ?>
> <tr>
> <td> </td>
> <td><?php echo $row_rsProducts['description']; ?></td>
> <td>$<?php echo $row_rsProducts['price']; ?></td>
> <td><form action="cart.php?action=add_item&itemid=<?php echo
> "$productid"
> ?>&color=<?php echo "$color"?>" method="post" name="size" target="_self">
> <table width="100%" border="0" cellspacing="0" cellpadding="0">
> <tr>
> <td colspan="2"><input type="radio" name="size" value="Small"
> />
> S
> <input type="radio" name="size" value="Medium" />
> M
> <input type="radio" name="size" value="Large" />
> L
> <input type="radio" name="size" value="Xtra Large" />
> XL
> <input type="radio" name="size" value="Double XL" />
> 2XL</td>
> </tr>
> <tr>
> <td width="64%"><input name="hiddenField" type="hidden"
> value="<?php echo $row_rsProducts['$color']; ?>">
> <input type="hidden" value="<?php echo
> $row_rsProducts['$product_id']; ?>"></td>
> <td width="36%"><input type="submit" name="Submit" value="Add
> To
> Cart" /></td>
> </tr>
> </table>
> </form></td>
> </tr>
> <tr>
> <td> </td>
> <td colspan="3"><hr /></td>
> </tr>
> <?php } while ($row_rsProducts = mysql_fetch_assoc($rsProducts)); ?>
> </table>
> <table width="76%" border="0" cellspacing="0" cellpadding="0">
> <tr>
> <td width="77%"> </td>
> <td width="23%" align="right"><table width="77%" border="0"
> cellspacing="1" cellpadding="1">
> <tr>
> <td width="48%" align="right"><?php if ($pageNum_rsProducts > 0)
> { //
> Show if not first page ?>
> <a href="<?php printf("%s?pageNum_rsProducts=%d%s",
> $currentPage,
> max(0, $pageNum_rsProducts - 1), $queryString_rsProducts);
> ?>">Previous</a>
> <?php } // Show if not first page ?></td>
> <td width="52%" align="right"><?php if ($pageNum_rsProducts <
> $totalPages_rsProducts) { // Show if not last page ?>
> <a href="<?php printf("%s?pageNum_rsProducts=%d%s",
> $currentPage,
> min($totalPages_rsProducts, $pageNum_rsProducts + 1),
> $queryString_rsProducts);
> ?>">Next</a>
> <?php } // Show if not last page ?></td>
> </tr>
> </table></td>
> </tr>
> </table>
> <p> </p>
> </body>
> </html>
> <?php
> mysql_free_result($rsProducts);
> ?>
>
> --------------------------------------------------------------------------------
> --------------------------------------------------------------------------------
> ------
> Cart.php code
>
> <?
> $dbServer = "localhost";
> $dbUser = "";
> $dbPass = "";
> $dbName = "store";
> mysql_connect($dbServer, $dbUser, $dbPass);
> mysql_select_db($dbName);
>
> session_start();
> session_set_cookie_params(0);
> $sessionid = $PHPSESSID;
> ?>
> <?php
> switch($action)
> {
> case "add_item":
> if(!isset($qty)){
> $qty=1;
> }
>
> AddItem($itemid,$sessionid,$qty,$size,$color);
> global $sessionid;
> include ("./show_cart.php");
> break;
> case "remove_item":
>
> RemoveItem($itemid,$sessionid,$size,$color);
>
> include ("./show_cart.php");
> break;
>
> case "check_out":
> include ("./checkout.inc");
> break;
> case "update_item":
> $sql = "UPDATE cart SET qty = '$qty' WHERE itemid='$itemid' AND
> size='$size' AND color='$color'";
> if(!(mysql_query($sql))){
> echo mysql_error();
> die();
> }
> include ("./show_cart.php");
> break;
> default:
> include ("./show_cart.php");
> }
>
>
>
>
> function AddItem($item,$sessionid,$qty,$size,$color){
> global $sessionid ;
> $session = $sessionid;
> if(!check_if_in_cart($item,$size,$color,$session)) {
> echo 'already in cart <a href="cart.php">Click Here</a> To view
> your
> cart and increase quantity';
> die();
> }
>
> $sql = 'INSERT INTO cart
> (sessionid,itemid,qty,size,color)VALUES("'.$sessio n.'","'.$item.'","'.$qty.'","'
> .$size.'","'.$color.'")';
> if(!(mysql_query($sql))){
> echo mysql_error();
> die();
> }
> }
> function RemoveItem($eyetem,$sessionid,$size,$color){
> $sql = "DELETE FROM cart WHERE itemid='$eyetem' AND size='$size'AND
> color='$color' AND sessionid='$sessionid'";
> mysql_query($sql);
>
> }
>
>
> function check_if_in_cart($item,$size,$color,$session){
> $sql="SELECT qty FROM cart WHERE sessionid='$session' AND itemid='$item'
> AND
> size='$size'AND color='$color'";
> if(!($result = mysql_query($sql))){
> echo mysql_error();
> die();
> }
> $numrows = mysql_num_rows($result);
> if($numrows > 0){
> return false;
> }else{
> return true;
> }
> }
> ?>
>
> --------------------------------------------------------------------------------
> --------------------------------------------------------------------------------
> ----
> Show_cart.php
>
> <?
> $bla="SELECT * FROM cart WHERE sessionid='$sessionid'";
> if(!($result = mysql_query($bla))){
> echo mysql_error();
> die();
> }
>
> //number of items in cart
> $numitems = mysql_num_rows($result);
> //now to print information. Edit this information as needed
> ?>
> <html>
> <head>
> <title>
> ::: He Is My ::: Global Ministries
> </title>
> <style type="type/css">
> p{font-family: arial}
> a {text-decoration: none}
> </style>
> </head>
> <body>
> <center>
> <h3>Your Cart Contains:
> <?=$numitems?>
> Item(s)</h3>
> <br>
> <table border=0 cellpadding=2 cellspacing=2>
> <tr>
> <td width="72" bgcolor="#993300"><div
> align="center">Description</div></td>
>
> <td width="35" bgcolor="#993300"><div align="center">Color</div></td>
>
> <td width="25" bgcolor="#993300"><div align="center">Size</div></td>
>
> <td width="51" bgcolor="#993300"><div
> align="center">Quantity</div></td>
>
> <td width="88" bgcolor="#993300"><div
> align="center">Update/Delete</div></td>
>
> <td width="31" bgcolor="#993300"><div align="center">Price</div></td>
> </tr>
> <?php
> while($row = mysql_fetch_array($result)){
> $iid = $row["itemid"];
> $result2 = mysql_query("SELECT * FROM products WHERE product_id =
> \"$iid\"");
> while ($row2 = mysql_fetch_array($result2)){
> $totalamount = $totalamount + ($row["qty"] * $row2["price"]);
> $totalamount = FormatCurrency($totalamount);
>
>
> ?>
> <form method="post"
> action="Original%20PHP%20FIles/cart.php?action=update_item&PHPSESSID=<?=$PHPSESS
> ID?>">
> <tr>
> <td><?=$row2["description"]?></td>
> <td><?=$row["color"]?></td>
> <td><?=$row["size"]?></td>
>
> <td><input type="text" size=2 name="qty" value="<?=$row["qty"]?>"><input
> type="hidden" name="itemid" value="<?=$row["itemid"]?>"><input
> type="hidden"
> name="size" value="<?=$row["size"]?>"><input type="hidden" name="color"
> value="<?=$row["color"]?>"></td>
> <td><font size="2">
> <input type="submit" value="Update">
> <a
> href="Original%20PHP%20FIles/cart.php?action=remove_item&itemid=<?=$row["itemid"
> ]?>&size=<?=$row["size"]?>&color=<?=$row["color"]?>">Delete
> Item From Shopping Cart</a></font></td>
> <td>
> <?php
>
> echo FormatCurrency($row2["price"]);
>
> ?>
>
> </td>
> </tr>
> </form>
> <?ph
twocans Guest
-
urbanactive #3
Re: Php Shopping Cart
what i mean is, the customer comes to the site and goes to products page, they
chose which shirt they want and then selectt thier size, then they click on the
add to cart button, this takes them to the cart, where they should be able to
see the description, color, size and price of the item they addded to the cart.
Im passing the description, and the size and the color is placed in a hidden
field. Im not sure what you mean by how am i filtering... . any help would be
great.
Mike
urbanactive Guest



Reply With Quote

