close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Problem pulling data from record set

Thread began 12/05/2011 9:34 am by bearpawwd431893 | Last modified 12/06/2011 9:37 am by Jason Byrnes | 1440 views | 8 replies |

bearpawwd431893

Problem pulling data from record set

When I add a dynamic add to cart button, I don't get the information for the data set for my shopping cart.

First I attached the recordset1 to the product result page:

Here is the code that I set the filter for form variable = ID: When I test it with ID= 101 it pulls up the information correctly.

<?php
//WA eCart Include
require_once("WA_eCart/eCart1_PHP.php");
?>
<?php require_once('Connections/bearpawwdcostdb.php'); ?>
<?php
$eCart1->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;
}
}

$colname_Recordset1 = "-1";
if (isset($_POST['ID'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['ID'] : addslashes($_POST['ID']);
}
mysql_select_db($database_bearpawwdcostdb, $bearpawwdcostdb);
$query_Recordset1 = sprintf("SELECT * FROM producttable1 WHERE ID = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $bearpawwdcostdb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
// WA eCart Redirect
if ($eCart1->redirStr != "") {
header("Location: ".$eCart1->redirStr);
}
?>


Next I insert the dynamic add to cart button with the ID value = 101

Here is the add to cart button cord:

<form name="eCart1_1_ATC_<?php echo $row_Recordset1["101"]; ?>" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".$_SERVER["QUERY_STRING"]:""; ?>">
<input type="hidden" name="eCart1_1_ID_Add" value="<?php echo $row_Recordset1["101"]; ?>" >
<input type="text" name="eCart1_1_Quantity_Add" value="1" size="4" >
<input type="image" src="WA_eCart/Images/Deep Jungle/Btn2_EN_addtocart.gif" border="0" class="eC_ImageButton" value="Add to Cart" name="eCart1_1_ATC">
</form>




But when I run the page and try to add the 101 product to my cart, nothing happens.

To test the page and shopping cart links, I set it up as a static button with all the information and the cart worked perfectly.

So why won't the dynamic add to cart button read the info from my record set and insert it into my shopping cart.

Sign in to reply to this post

Jason ByrnesWebAssist

change:
<input type="hidden" name="eCart1_1_ID_Add" value="<?php echo $row_Recordset1["101"]; ?>" >


to:
<input type="hidden" name="eCart1_1_ID_Add" value="101" >

Sign in to reply to this post

bearpawwd431893

Can't get data

That is the way I originally wrote the code and it didn't work. I did it again and it still doesn't work.

?

Sign in to reply to this post

bearpawwd431893

Still doesn't work

Any more ideas what is wrong?

Sign in to reply to this post

Jason ByrnesWebAssist

send a copy of the page in a zip archive so i can see the code in context

Sign in to reply to this post

bearpawwd431893

Here is the file.

Attached Files
bearpawwd431893.pdf
Sign in to reply to this post

Jason ByrnesWebAssist

your product recordset is filtered on a posted form element named ID which does not exist when the add to cart button is pressed.


normally, a product detail page would use a querystring variable instead of a posted form variable.

change:
<input type="hidden" name="eCart1_1_ID_Add" value="101" >

to:
<input type="hidden" name="eCart1_1_ID_Add" value="101" >
<input type="hidden" name="ID" value="101" >

Sign in to reply to this post

bearpawwd431893

That worked perfect. However, I don't understand why. Is it because when the add to cart button is pressed, then the posted form element ID is created. Is that why I need both lines:


<input type="hidden" name="eCart1_1_ID_Add" value="101" >
<input type="hidden" name="ID" value="101" >

because it is querying for the value in the first line and the second line creates the ID = 101?


I am just trying to understand this so that I don't make the mistake again.


You and this forum are a great help to us less knowledgeable in php code.

Sign in to reply to this post

Jason ByrnesWebAssist

normally the second line would not be needed if the detail page where set to use a querystring variable.

your detail page is set to use a posted value, so the posted value needs to be included in the add to cart form.

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