| | |
How to add amount of items in shopping cart? Need urgent help!
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Are you using a session to store the stuff in the cart or what? I'd suggest creating a session for the user with the following variables:
array $quantity
array $product
each element of those arrays will contain the info for an item. ($quantity[0] has the quantity of the first item and $product[0] has the name or item number or id of the product).
array $quantity
array $product
each element of those arrays will contain the info for an item. ($quantity[0] has the quantity of the first item and $product[0] has the name or item number or id of the product).
★ "If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
•
•
Join Date: Jul 2008
Posts: 9
Reputation:
Solved Threads: 0
•
•
•
•
Are you using a session to store the stuff in the cart or what? I'd suggest creating a session for the user with the following variables:
array $quantity
array $product
each element of those arrays will contain the info for an item. ($quantity[0] has the quantity of the first item and $product[0] has the name or item number or id of the product).
Here's a code to my shopping cart
<?php require_once('../Connections/myDatabase.php'); ?>
<?php session_start(); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if ((isset($_POST['cartid'])) && ($_POST['cartid'] != "")) {
$deleteSQL = sprintf("DELETE FROM cart WHERE cartid=%s",
GetSQLValueString($_POST['cartid'], "int"));
mysql_select_db($database_myDatabase, $myDatabase);
$Result1 = mysql_query($deleteSQL, $myDatabase) or die(mysql_error());
$deleteGoTo = "DeleteSuccessfully.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
mysql_select_db($database_myDatabase, $myDatabase);
$query_Cart = "SELECT * FROM cart";
$Cart = mysql_query($query_Cart, $myDatabase) or die(mysql_error());
$row_Cart = mysql_fetch_assoc($Cart);
$totalRows_Cart = mysql_num_rows($Cart);
?>
<!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=utf-8" />
<title>Untitled Document</title>
<link href="../eb-main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
.style2 {font-size: small
}
body {
background-color: #FFFFFF;
}
.style3 {color: #000000}
.style6 {font-size: 18px}
.style7 {color: #FFFFFF; font-size: medium; }
-->
</style>
</head>
<body>
<div id="wrapper">
<div class="style1" id="banner">
<div align="center">
<p><img src="../Images/BooksInc Banner.jpg" width="751" height="300" /></p>
<p>
<map name="Map" id="Map">
<area shape="rect" coords="2,0,145,63" href="../Pages/EventsMgt.html" />
<area shape="rect" coords="154,0,283,63" href="../Pages/PA System.html" />
<area shape="rect" coords="299,1,449,63" href="../Pages/RehearsalSuiteRental.html" />
<area shape="rect" coords="651,-4,762,62" href="../Pages/BandTshirtDesign.html" />
</map>
<img src="../Images/BookHavenMenu.jpg" width="751" height="50" border="0" usemap="#Map2" />
<map name="Map2" id="Map2"><area shape="rect" coords="3,3,104,47" href="Home.php" />
<area shape="rect" coords="124,3,277,47" href="SelectUrBooks.php" />
<area shape="rect" coords="301,3,410,49" href="Transaction.php" />
</map></p>
</div>
Welcome, {stranger!}</div>
<p><span class="style2"><span class="style1"> </span></span></p>
<p align="right">
<a href="SelectUrBooks.php" class="style7">Continue Shopping</a>
<table width="83%" border="1">
<?php do { ?>
<form id="form1" name="form1" method="POST" action="">
<tr>
<td width="23%" scope="col"><span class="style6">
<input name="cartid" type="hidden" id="cartid" value="<?php echo $row_Cart['cartid']; ?>" />
<?php echo $row_Cart['title']; ?></span></td>
<td width="23%" scope="col"><span class="style6"><?php echo $row_Cart['author']; ?></span></td>
<td width="16%" scope="col"><span class="style6">$<?php echo $row_Cart['price']; ?></span></td>
<td width="18%" scope="col"><span class="style6"><?php echo $row_Cart['category']; ?></span></td>
<td width="5%" scope="col"><label>
<input name="NoOfItems" type="text" id="NoOfItems" size="5" />
</label></td>
<td width="8%" scope="col"><input type="submit" name="Updatebtn" id="Updatebtn" value="Update" /></td>
<td width="7%" scope="col"><label>
<input type="submit" name="DeleteBtn" id="DeleteBtn" value="Delete" />
</label></td>
</tr> </form>
<?php } while ($row_Cart = mysql_fetch_assoc($Cart)); ?>
</table>
<p align="right"> <span class="style6"> <a href="ConfirmDelete.php"></a> </span>
<p> </p>
<div class="style1" id="footer">
<div align="center">
<p class="style2"> </p>
<p class="style2"> </p>
<p class="style2"> </p>
<p class="style2"> </p>
<p class="style2"> </p>
<p class="style2"> </p>
<p class="style2"><span class="style3"><a href="Home.php">Home</a><span class="style1"> | </span><a href="SelectUrBooks.php">Select ur Books!</a> <span class="style1">| Transaction | Checkout | Transaction Summary</span></span></p>
<p>© Book Haven productions</p>
</div>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($Cart);
?>If possible you could guide my through the steps cos im a beginner in PHP.
Hmm, you've got an input for the quantity. Did you add that in the hope of getting it to work? Does the cart work how it is without quantity? What do you actually mean by "add the amount of items in the shopping cart"?.
★ "If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: php pop-up link pls help
- Next Thread: visitor Details
| Thread Tools | Search this Thread |
apache api array basic beginner broken cache cakephp class cms code computing confirm countingeverycharactersfromastring cron curl customizableitems database date delete dynamic echo email error fcc file filter folder form forms forum freelancing function functions gc_maxlifetime google header headmethod howtowriteathesis href htaccess html iframe image include incode ip javascript joomla limit link login malfunction match memmory memory menu method mod_rewrite multiple mysql navigation neutrality oop pagerank parsing paypal pdf php phpmysql query question random recursiveloop root script search select server sessions sms snippet soap source space sql support! system table template thesishelp trouble tutorial upload url variable video web window.onbeforeunload=closeme; youtube





