close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

adding multiple products to car wiht check box

Thread began 12/18/2009 12:40 am by elyas218928 | Last modified 12/21/2009 8:06 pm by Jason Byrnes | 1039 views | 5 replies |

elyas218928

adding multiple products to cart wiht check box

i am having problem adding multiple products to cart with check box.

i followed the instructions on webassist recipe file and i am using data assist and ecart.

when i add one product it adds all the products to cart. i cant get only one product as its ticked to be added to cart.

i have tried so hard but i cant get it to work

this is my code.
-----------------------------
<?php require_once('Connections/conn.php'); ?>
<?php
//WA eCart Include
require_once("WA_eCart/eCart1_PHP.php");
?>
<?php
$eCart1->GetContent();
?>
<?php
//WA Database Search Include
require_once("WADbSearch/HelperPHP.php");
?>
<?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;
}
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_conn, $conn);
$query_Recordset1 = "SELECT * FROM comp";
setQueryBuilderSource($query_Recordset1,$WADbSearch1,false);
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: Recordset1;
//Searchpage: ;
//Form: ;
$WADbSearch1_DefaultWhere = "AND id=0";
if (!session_id()) session_start();
if (isset($_POST["AddToCartButton_x"])) {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//keyword array declarations

//comparison list additions
$WADbSearch1->addComparisonFromList("id","ATCCheck","AND","=",1);

//save the query in a session variable
if (1 == 1) {
$_SESSION["WADbSearch1_wa"]=$WADbSearch1->whereClause;
}
}
else {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//get the filter definition from a session variable
if (1 == 1) {
if (isset($_SESSION["WADbSearch1_wa"]) && $_SESSION["WADbSearch1_wa"] != "") {
$WADbSearch1->whereClause = $_SESSION["WADbSearch1_wa"];
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
$WADbSearch1->whereClause = str_replace("\\''", "''", $WADbSearch1->whereClause);
$WADbSearch1whereClause = '';
?>
<?php
// WA eCart Get Info From RS
if (isset($_POST["AddToCartButton_x"]) && isset($totalRows_Recordset1) && $totalRows_Recordset1 > 0) {
$Redirect_redirStr="";
do {
$eCart1_itemID = floatval("".$row_Recordset1['id'] ."");
$eCart1_itemName = "".$row_Recordset1['name'] ."";
$eCart1_itemDescription = "";
$eCart1_itemWeight = floatval("");
$eCart1_itemQuantity = floatval("1");
$eCart1_itemPrice = floatval("");

$eCart1->AddToCart(1, "", $eCart1_itemID, $eCart1_itemName, $eCart1_itemDescription, $eCart1_itemWeight, $eCart1_itemQuantity, $eCart1_itemPrice);
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
if ($Redirect_redirStr != "") {
$eCart1->redirStr = $Redirect_redirStr;
}
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
<?php
// WA eCart Redirect
if ($eCart1->redirStr != "") {
header("Location: ".$eCart1->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>Untitled Document</title>
<link href="WA_eCart/CSS/eC_Clean_Slate_Verdana.css" rel="stylesheet" type="text/css" />
<link href="WA_eCart/CSS/eC_Simple_Slate_Verdana.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" border="0">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

<form method="post" id="add_to_cart">
<table width="100%" border="0">
<tr>
<td width="17%"><input type="image" name="AddToCartButton" id="AddToCartButton" src="WA_eCart/Images/Slate/Btn4_EN_addtocart.gif" /></td>
<td width="28%">&nbsp;</td>
<td width="5%">&nbsp;</td>
<td width="17%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['name']; ?></td>
<td width="28%">&nbsp;</td>
<td width="5%"><input name="ATCCheck" type="checkbox" id="ATCCheck" value="<?php echo $row_Recordset1['id']; ?>" /></td>
<td width="17%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<tr>
<td>&nbsp;</td>
<td width="28%">&nbsp;</td>
<td width="5%">&nbsp;</td>
<td width="17%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
</table>
<br />
<br />
</form>

<table width="100%" border="0">
<tr>
<td>&nbsp;</td>
</tr>
</table>

</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
------------------------------------------------

Sign in to reply to this post

Jason ByrnesWebAssist

1) The checkbox name needs to end in "[]"

php:
<td width="5%"><input name="ATCCheck[]" type="checkbox" id="ATCCheck" value="<?php echo $row_Recordset1['id']; ?>" /></td>





2) The default where clause should be 0 != 0 and the trigger should be the chkbox:
change:

php:
$WADbSearch1_DefaultWhere = "AND id=0";

if (!session_id()) session_start();
if (isset($_POST["AddToCartButton_x"])) {




to:

php:
$WADbSearch1_DefaultWhere = " 0 != 0";

if (!session_id()) session_start();
if (isset($_POST["ATCCheck"])) {
Sign in to reply to this post

elyas218928

still not working

hi jason

thanks for your replay but after i made the changes you asked i still have the same problem.

even if i don't tick a check box and click add to cart it adds all products on the list to cart.

here is my modified code.

---------------------------
<?php require_once('Connections/conn.php'); ?>
<?php
//WA eCart Include
require_once("WA_eCart/eCart1_PHP.php");
?>
<?php
$eCart1->GetContent();
?>
<?php
//WA Database Search Include
require_once("WADbSearch/HelperPHP.php");
?>

<?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;
}
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_conn, $conn);
$query_Recordset1 = "SELECT * FROM comp";
setQueryBuilderSource($query_Recordset1,$WADbSearch1,false);
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: Recordset1;
//Searchpage: ;
//Form: ;
$WADbSearch1_DefaultWhere = "0 != 0";
if (!session_id()) session_start();
if (isset($_POST["ATCCheck"])) {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//keyword array declarations

//comparison list additions
$WADbSearch1->addComparisonFromList("id","ATCCheck","AND","=",1);

//save the query in a session variable
if (1 == 1) {
$_SESSION["WADbSearch1_wa"]=$WADbSearch1->whereClause;
}
}
else {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//get the filter definition from a session variable
if (1 == 1) {
if (isset($_SESSION["WADbSearch1_wa"]) && $_SESSION["WADbSearch1_wa"] != "") {
$WADbSearch1->whereClause = $_SESSION["WADbSearch1_wa"];
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
$WADbSearch1->whereClause = str_replace("\\''", "''", $WADbSearch1->whereClause);
$WADbSearch1whereClause = '';
?>
<?php
// WA eCart Get Info From RS
if (isset($_POST["AddToCartButton_x"]) && isset($totalRows_Recordset1) && $totalRows_Recordset1 > 0) {
$Redirect_redirStr="";
do {
$eCart1_itemID = floatval("".$row_Recordset1['id'] ."");
$eCart1_itemName = "".$row_Recordset1['name'] ."";
$eCart1_itemDescription = "";
$eCart1_itemWeight = floatval("0");
$eCart1_itemQuantity = floatval("1");
$eCart1_itemPrice = floatval("0");

$eCart1->AddToCart(1, "", $eCart1_itemID, $eCart1_itemName, $eCart1_itemDescription, $eCart1_itemWeight, $eCart1_itemQuantity, $eCart1_itemPrice);
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
if ($Redirect_redirStr != "") {
$eCart1->redirStr = $Redirect_redirStr;
}
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
-----------------------

and my form is

<form method="post" id="add_to_cart">
<table width="100%" border="0">
<tr>
<td width="17%"><input type="image" name="AddToCartButton" id="AddToCartButton" src="WA_eCart/Images/Slate/Btn4_EN_addtocart.gif" /></td>
<td width="28%">&nbsp;</td>
<td width="5%">&nbsp;</td>
<td width="17%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['name']; ?></td>
<td width="28%">&nbsp;</td>
<td width="5%"><input name="ATCCheck[]" type="checkbox" id="ATCCheck" value="<?php echo $row_Recordset1['id']; ?>" /></td>
<td width="17%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<tr>
<td>&nbsp;</td>
<td width="28%">&nbsp;</td>
<td width="5%">&nbsp;</td>
<td width="17%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
</table>
<br />
<br />
</form>

------------------------

if i move the Data assist code before the record set i get no result at all.

looking forward to a solution

cheers

Sign in to reply to this post

Jason ByrnesWebAssist

The recordset code is before the DataAssist search code, the recordset must be created after the DataAssist search code creates the where clause.

Sign in to reply to this post

elyas218928

problem not solved

hi jason

i moved the data Assist code before the recordset but now i get only one record displayed and my rpeat region is set to 10.

even when there is only one record displayed if i dont tick the check box and click add to cart it adds it to cart. this is my code now.

-----------------------
<?php require_once('Connections/conn.php'); ?>
<?php
//WA eCart Include
require_once("WA_eCart/eCart1_PHP.php");
?>
<?php
$eCart1->GetContent();
?>
<?php
//WA Database Search Include
require_once("WADbSearch/HelperPHP.php");
?>
<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: Recordset1;
//Searchpage: ;
//Form: ;
$WADbSearch1_DefaultWhere = "0 != 0";
if (!session_id()) session_start();
if (isset($_POST["ATCCheck"])) {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//keyword array declarations

//comparison list additions
$WADbSearch1->addComparisonFromList("id","ATCCheck","AND","=",1);

//save the query in a session variable
if (1 == 1) {
$_SESSION["WADbSearch1_wa"]=$WADbSearch1->whereClause;
}
}
else {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//get the filter definition from a session variable
if (1 == 1) {
if (isset($_SESSION["WADbSearch1_wa"]) && $_SESSION["WADbSearch1_wa"] != "") {
$WADbSearch1->whereClause = $_SESSION["WADbSearch1_wa"];
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
$WADbSearch1->whereClause = str_replace("\\''", "''", $WADbSearch1->whereClause);
$WADbSearch1whereClause = '';
?>
<?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;
}
}

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_conn, $conn);
$query_Recordset1 = "SELECT * FROM comp";
setQueryBuilderSource($query_Recordset1,$WADbSearch1,false);
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
<?php
// WA eCart Get Info From RS
if (isset($_POST["AddToCartButton_x"]) && isset($totalRows_Recordset1) && $totalRows_Recordset1 > 0) {
$Redirect_redirStr="";
do {
$eCart1_itemID = floatval("".$row_Recordset1['id'] ."");
$eCart1_itemName = "".$row_Recordset1['name'] ."";
$eCart1_itemDescription = "";
$eCart1_itemWeight = floatval("0");
$eCart1_itemQuantity = floatval("1");
$eCart1_itemPrice = floatval("0");

$eCart1->AddToCart(1, "", $eCart1_itemID, $eCart1_itemName, $eCart1_itemDescription, $eCart1_itemWeight, $eCart1_itemQuantity, $eCart1_itemPrice);
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
if ($Redirect_redirStr != "") {
$eCart1->redirStr = $Redirect_redirStr;
}
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
-------------------------------------------------------------

<form method="post" id="add_to_cart">
<table width="100%" border="0">
<tr>
<td width="17%"><input type="image" name="AddToCartButton" id="AddToCartButton" src="WA_eCart/Images/Slate/Btn4_EN_addtocart.gif" /></td>
<td width="28%">&nbsp;</td>
<td width="5%">&nbsp;</td>
<td width="17%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['name']; ?></td>
<td width="28%">&nbsp;</td>
<td width="5%"><input name="ATCCheck[]" type="checkbox" id="ATCCheck" value="<?php echo $row_Recordset1['id']; ?>" /></td>
<td width="17%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<tr>
<td>&nbsp;</td>
<td width="28%">&nbsp;</td>
<td width="5%">&nbsp;</td>
<td width="17%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
</table>
<br />
<br />
</form>

--------------------------------------------

Sign in to reply to this post

Jason ByrnesWebAssist

The main problem is that you only have one recordset on the page.


you need to have two recordsets on the page, one to show all of the items and create the Repeat region. the second one to add the selected items to the cart. The first one will not be filtered at all, the second will be filtered by the DataAssist search server behavior.

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...