close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

eCart Recordsets

Thread began 8/29/2012 5:36 pm by Loretta439108 | Last modified 8/31/2012 11:06 am by Jason Byrnes | 900 views | 6 replies |

Loretta439108

eCart Recordsets

Hello,

I'm selling a product that has various sizes with corresponding prices (not incremented) and I'm having difficulty coordinating the recordsets, add to cart behaviors and pull down menus.
I have three tables - an item table, a linking itemoptions table and an options table that has the sizes, prices and weights in it.

I can't seem to get my add to cart buttons to add anything to my cart page. Any help would be greatly appreciated!

Here's the code:

<?php
//WA eCart Include
require_once("WA_eCart/CarteBlank_PHP.php");
?>
<?php require_once('Connections/connSpectrum.php'); ?>
<?php
$CarteBlank->GetContent();
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}

mysql_select_db($database_connSpectrum, $connSpectrum);
$query_rsItems = "SELECT ItemID, ItemCatID, ItemName, ItemDesc, ItemSKU, ItemImage FROM items ORDER BY ItemID ASC";
$rsItems = mysql_query($query_rsItems, $connSpectrum) or die(mysql_error());
$row_rsItems = mysql_fetch_assoc($rsItems);
$totalRows_rsItems = mysql_num_rows($rsItems);
?>


<!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>Product Page</title>
<link href="css/global.css" rel="stylesheet" type="text/css" />
</head>

<body background="img/metgrad.jpg">
<div id="container">
<div id="banner">
<p><img src="img/header2.gif" alt="W" width="950" height="141" longdesc="http://www.fff.com/" /></p>
</div>



<?php do { ?>
<?php
$varItem_rsSizes = "1";
if (isset($row_rsItems['ItemID'])) {
$varItem_rsSizes = $row_rsItems['ItemID'];
}
mysql_select_db($database_connSpectrum, $connSpectrum);
$query_rsSizes = sprintf("SELECT items.ItemID, options.OptionID, options.Option, options.OptionPrice, options.OptionWeight FROM items LEFT OUTER JOIN itemoptions ON items.ItemID = itemoptions.ItemID INNER JOIN options ON itemoptions.OptionID = options.OptionID WHERE items.ItemID = %s", GetSQLValueString($varItem_rsSizes, "int"));
$rsSizes = mysql_query($query_rsSizes, $connSpectrum) or die(mysql_error());
$row_rsSizes = mysql_fetch_assoc($rsSizes);
$totalRows_rsSizes = mysql_num_rows($rsSizes);

$paramOption_rsSizeLookup = "-1";
if (isset($_POST['eCarteBlank_1_size_Add'])) {
$paramOption_rsSizeLookup = $_POST['eCarteBlank_1_size_Add'];
}
$paramItem_rsSizeLookup = "-1";
if (isset($_POST['eCarteBlank_1_ID_Add'])) {
$paramItem_rsSizeLookup = $_POST['eCarteBlank_1_ID_Add'];
}
mysql_select_db($database_connSpectrum, $connSpectrum);
$query_rsSizeLookup = sprintf("SELECT options.OptionID, options.`Option`, options.OptionPrice, options.OptionWeight, itemoptions.ItemOptionID FROM options INNER JOIN itemoptions ON options.OptionID = itemoptions.OptionID WHERE itemoptions.OptionID = %s AND itemoptions.OptionID = %s", GetSQLValueString($paramOption_rsSizeLookup, "int"),GetSQLValueString($paramItem_rsSizeLookup, "int"));
$rsSizeLookup = mysql_query($query_rsSizeLookup, $connSpectrum) or die(mysql_error());
$row_rsSizeLookup = mysql_fetch_assoc($rsSizeLookup);
$totalRows_rsSizeLookup = mysql_num_rows($rsSizeLookup);
?>
<?php
// WA eCart AddToCart
if (isset($_POST["CarteBlank_1_ATC"]) || isset($_POST["CarteBlank_1_ATC_x"])) {
$ATC_itemID = $_POST["CarteBlank_1_ID_Add"];
$ATC_AddIfIn = 0;
$ATC_RedirectAfter = "";
$ATC_RedirectIfIn = "";
if (isset($totalRows_rsItems) && $totalRows_rsItems > 0) {
$row_rsItems = WAEC_findRecordMySQL($rsItems, "ItemID", $ATC_itemID);
if ($row_rsItems) {
$ATC_itemName = "".$row_rsItems['ItemName'] ."";// column binding
$ATC_itemDescription = "".$row_rsItems['ItemDesc'] ."";// column binding
$ATC_itemThumbnail = "img/small/".$row_rsItems['ItemImage'] ."";// column binding
$ATC_itemWeight = floatval("".$row_rsSizeLookup['OptionWeight'] ."");// column binding
$ATC_itemQuantity = "".$_POST["CarteBlank_1_Quantity_Add"] ."";// column binding
$ATC_itemPrice = floatval("".$row_rsSizeLookup['OptionPrice'] ."");// column binding
$ATC_itemSize = "".$row_rsSizeLookup['Option'] ."";// column binding
$ATC_itemSKU = "".$row_rsItems['ItemSKU'] ."";// column binding
mysql_data_seek($rsItems, 0);
$row_rsItems = mysql_fetch_assoc($rsItems);
}
}
$ATC_itemQuantity = floatval($ATC_itemQuantity);
if (is_numeric($ATC_itemQuantity) && $ATC_itemQuantity != 0) {
$CarteBlank->AddToCart($ATC_AddIfIn, $ATC_RedirectIfIn, $ATC_itemID, $ATC_itemName, $ATC_itemDescription, $ATC_itemThumbnail, $ATC_itemWeight, $ATC_itemQuantity, $ATC_itemPrice, $ATC_itemSize, $ATC_itemSKU);
if ($ATC_RedirectAfter != "" && $CarteBlank->redirStr == "") {
$CarteBlank->redirStr = $ATC_RedirectAfter;
}
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
}
else {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF'];
}
}
}
?>
<?php
// WA eCart Redirect
if ($CarteBlank->redirStr != "") {
header("Location: ".$CarteBlank->redirStr);
}
?>
<div class="ul">
<p><?php echo $row_rsItems['ItemName']; ?></p>
<p><?php echo $row_rsItems['ItemDesc']; ?></p>
<p><?php echo $row_rsItems['ItemSKU']; ?></p>
<p><img src="img/small/<?php echo $row_rsItems['ItemImage']; ?>" alt="image" /></p>
<p>&nbsp;<form name="CarteBlank_1_ATC_<?php echo $row_rsItems["ItemID"]; ?>" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>">
<p>
<input type="hidden" name="CarteBlank_1_ID_Add" value="<?php echo $row_rsItems["ItemID"]; ?>" >
<input type="text" name="CarteBlank_1_Quantity_Add" value="1" size="4" >
<label for="eCarteBlank_1_size_Add">Sizes & Prices</label>
<select name="eCarteBlank_1_size_Add" id="eCarteBlank_1_size_Add">
<?php
do {
?>
<option value="<?php echo $row_rsSizes['ItemID']?>"><?php echo $row_rsSizes['Option']?>&nbsp; &nbsp;$<?php echo $row_rsSizes['OptionPrice']?></option>
<?php
} while ($row_rsSizes = mysql_fetch_assoc($rsSizes));
$rows = mysql_num_rows($rsSizes);
if($rows > 0) {
mysql_data_seek($rsSizes, 0);
$row_rsSizes = mysql_fetch_assoc($rsSizes);
}
?>
</select>
</p>
<p>
<input type="image" src="img/PNG/addtocart.png" border="0" class="eC_ImageButton" value="Add to Cart" name="CarteBlank_1_ATC">
</p>
</form>
</p>

<p>&nbsp;</p>
</div>

<?php } while ($row_rsItems = mysql_fetch_assoc($rsItems)); ?>

</div>
</body>
</html>

<?php
mysql_free_result($rsItems);

mysql_free_result($rsSizes);

mysql_free_result($rsSizeLookup);
?>

Thanks!

Sign in to reply to this post

Jason ByrnesWebAssist

you have the code for the add to cart button behavior code inside of a loop, this is why it is not working.

the add to cart button behavior code should be in the head of the page.

Sign in to reply to this post

Loretta439108

Thanks so much! eCart had automatically inserted the code after the rsSizes recordset that was in the loop.

The add to cart button works now except that the values for the weight, size and price are all 0. Are my recordsets the problem, or is there something else that I'm missing?

Here's the revised code:

<?php
//WA eCart Include
require_once("WA_eCart/CarteBlank_PHP.php");
?>
<?php require_once('Connections/connSpectrum.php'); ?>
<?php
$CarteBlank->GetContent();
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}

mysql_select_db($database_connSpectrum, $connSpectrum);
$query_rsItems = "SELECT ItemID, ItemCatID, ItemName, ItemDesc, ItemSKU, ItemImage FROM items ORDER BY ItemID ASC";
$rsItems = mysql_query($query_rsItems, $connSpectrum) or die(mysql_error());
$row_rsItems = mysql_fetch_assoc($rsItems);
$totalRows_rsItems = mysql_num_rows($rsItems);

$paramOption_rsSizeLookup = "-1";
if (isset($_POST['eCarteBlank_1_size_Add'])) {
$paramOption_rsSizeLookup = $_POST['eCarteBlank_1_size_Add'];
}
$paramItem_rsSizeLookup = "-1";
if (isset($_POST['eCarteBlank_1_ID_Add'])) {
$paramItem_rsSizeLookup = $_POST['eCarteBlank_1_ID_Add'];
}
mysql_select_db($database_connSpectrum, $connSpectrum);
$query_rsSizeLookup = sprintf("SELECT options.OptionID, options.`Option`, options.OptionPrice, options.OptionWeight, itemoptions.ItemOptionID FROM options INNER JOIN itemoptions ON options.OptionID = itemoptions.OptionID WHERE itemoptions.OptionID = %s AND itemoptions.OptionID = %s", GetSQLValueString($paramOption_rsSizeLookup, "int"),GetSQLValueString($paramItem_rsSizeLookup, "int"));
$rsSizeLookup = mysql_query($query_rsSizeLookup, $connSpectrum) or die(mysql_error());
$row_rsSizeLookup = mysql_fetch_assoc($rsSizeLookup);
$totalRows_rsSizeLookup = mysql_num_rows($rsSizeLookup);
?>
<?php
// WA eCart AddToCart
if (isset($_POST["CarteBlank_1_ATC"]) || isset($_POST["CarteBlank_1_ATC_x"])) {
$ATC_itemID = $_POST["CarteBlank_1_ID_Add"];
$ATC_AddIfIn = 0;
$ATC_RedirectAfter = "cart.php";
$ATC_RedirectIfIn = "";
if (isset($totalRows_rsItems) && $totalRows_rsItems > 0) {
$row_rsItems = WAEC_findRecordMySQL($rsItems, "ItemID", $ATC_itemID);
if ($row_rsItems) {
$ATC_itemName = "".$row_rsItems['ItemName'] ."";// column binding
$ATC_itemDescription = "".$row_rsItems['ItemDesc'] ."";// column binding
$ATC_itemThumbnail = "img/small/".$row_rsItems['ItemImage'] ."";// column binding
$ATC_itemWeight = floatval("".$row_rsSizeLookup['OptionWeight'] ."");// column binding
$ATC_itemQuantity = "".$_POST["CarteBlank_1_Quantity_Add"] ."";// column binding
$ATC_itemPrice = floatval("".$row_rsSizeLookup['OptionPrice'] ."");// column binding
$ATC_itemSize = "".$row_rsSizeLookup['Option'] ."";// column binding
$ATC_itemSKU = "".$row_rsItems['ItemSKU'] ."";// column binding
mysql_data_seek($rsItems, 0);
$row_rsItems = mysql_fetch_assoc($rsItems);
}
}
$ATC_itemQuantity = floatval($ATC_itemQuantity);
if (is_numeric($ATC_itemQuantity) && $ATC_itemQuantity != 0) {
$CarteBlank->AddToCart($ATC_AddIfIn, $ATC_RedirectIfIn, $ATC_itemID, $ATC_itemName, $ATC_itemDescription, $ATC_itemThumbnail, $ATC_itemWeight, $ATC_itemQuantity, $ATC_itemPrice, $ATC_itemSize, $ATC_itemSKU);
if ($ATC_RedirectAfter != "" && $CarteBlank->redirStr == "") {
$CarteBlank->redirStr = $ATC_RedirectAfter;
}
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
}
else {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF'];
}
}
}
?>
<?php
// WA eCart Redirect
if ($CarteBlank->redirStr != "") {
header("Location: ".$CarteBlank->redirStr);
}
?>
<!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>Product Page</title>
<link href="css/global.css" rel="stylesheet" type="text/css" />
</head>

<body background="img/metgrad.jpg">
<div id="container">
<div id="banner">
<p><img src="img/header2.gif" alt="" width="950" height="141" longdesc="http://www.fff.com/" /></p>
</div>


<?php do { ?>
<?php
$varItem_rsSizes = "1";
if (isset($row_rsItems['ItemID'])) {
$varItem_rsSizes = $row_rsItems['ItemID'];
}
mysql_select_db($database_connSpectrum, $connSpectrum);
$query_rsSizes = sprintf("SELECT items.ItemID, options.OptionID, options.Option, options.OptionPrice, options.OptionWeight FROM items LEFT OUTER JOIN itemoptions ON items.ItemID = itemoptions.ItemID INNER JOIN options ON itemoptions.OptionID = options.OptionID WHERE items.ItemID = %s", GetSQLValueString($varItem_rsSizes, "int"));
$rsSizes = mysql_query($query_rsSizes, $connSpectrum) or die(mysql_error());
$row_rsSizes = mysql_fetch_assoc($rsSizes);
$totalRows_rsSizes = mysql_num_rows($rsSizes);

?>

<div class="ul">
<p><?php echo $row_rsItems['ItemName']; ?></p>
<p><?php echo $row_rsItems['ItemDesc']; ?></p>
<p><?php echo $row_rsItems['ItemSKU']; ?></p>
<p><img src="img/small/<?php echo $row_rsItems['ItemImage']; ?>" alt="image" /></p>
<p>&nbsp;<form name="CarteBlank_1_ATC_<?php echo $row_rsItems["ItemID"]; ?>" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>">
<p>
<input type="hidden" name="CarteBlank_1_ID_Add" value="<?php echo $row_rsItems["ItemID"]; ?>" >
<input type="text" name="CarteBlank_1_Quantity_Add" value="1" size="4" >
<label for="eCarteBlank_1_size_Add">Sizes & Prices</label>
<select name="eCarteBlank_1_size_Add" id="eCarteBlank_1_size_Add">
<?php
do {
?>
<option value="<?php echo $row_rsSizes['ItemID']?>"><?php echo $row_rsSizes['Option']?>&nbsp; &nbsp;$<?php echo $row_rsSizes['OptionPrice']?></option>
<?php
} while ($row_rsSizes = mysql_fetch_assoc($rsSizes));
$rows = mysql_num_rows($rsSizes);
if($rows > 0) {
mysql_data_seek($rsSizes, 0);
$row_rsSizes = mysql_fetch_assoc($rsSizes);
}
?>
</select>
</p>
<p>
<input type="image" src="img/PNG/addtocart.png" border="0" class="eC_ImageButton" value="Add to Cart" name="CarteBlank_1_ATC">
</p>
</form>
</p>

<p>&nbsp;</p>
</div>
<!-- An associative fetch array-which returns one row of date
at a time, in an array format -->
<?php } while ($row_rsItems = mysql_fetch_assoc($rsItems)); ?>

</div>
</body>
</html>

<?php
mysql_free_result($rsItems);

mysql_free_result($rsSizes);

mysql_free_result($rsSizeLookup);
?>
Thanks much, I'm grateful for your help.

Sign in to reply to this post

Loretta439108

Actually the size is blank and the price, weight and total are 0.00.

Sign in to reply to this post

Jason ByrnesWebAssist

the option select list value should use the OptionID column instead of ItemID


the size lookup recordset, you the where clause using the itemoptions.OptionID twice

WHERE itemoptions.OptionID = paramOption AND itemoptions.OptionID = paramItem

it should be:
WHERE itemoptions.OptionID = paramOption AND itemoptions.ItemID = paramItem

Sign in to reply to this post

Loretta439108

Hello,

I changed the option select list value to OptionID.

When I attempt to edit the rsLookup recordset I get the following error message: "While executing applyServerBehavior in Recordset.htm, a JavaScript error occurred."
I edited the code manually and changed the WHERE clause, but I'm still getting no size in the cart and the weight, price and total are 0's.

Thanks again...

Sign in to reply to this post

Jason ByrnesWebAssist

I have created a support ticket so we can look into this issue further.

To view and edit your support ticket, please log into your support history:
supporthistory.php

If anyone else is experiencing this same issue, please append to this thread.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...