Solved

page functions when there is a 'stock' quantity in the recordset. But if quantity is zero - problem

Posted on 2007-11-16
16
547 Views
Last Modified: 2010-04-21
I have an add to cart feature on this page - which if the quantity requested is more than the stock available (drawn from RSStock) there is a redirect to an out of stock page. This all works if there is a quantity of stock i.e. if 6 are requested but there is four in stock the page redirects to the out of stock with a 'sorry we've only got 4 of the six you wanted..etc

But if there is None in stock I get this instead of the redirect to the out of stock page with the 'out of stock' message:

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/MR07 OffLine/detail.asp, line 201

I know this is to do with the zero, but zero is a number and the stock id exists? The page works fine otherwise....

Any ideas?

Thanks

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="WA_eCart/WA_eCart_Definition_VB.asp" -->
<!--#include file="WA_eCart/magecart_VB.asp" -->
<!--#include file="Connections/MagicalRooms.asp" -->
<% 'Sub dbCleanUp()
'  RsPrice.Close()
'  RsStock.Close()
'  connConnection.Close()
'  Set RsPrice = Nothing
'  Set RsStock = Nothing
'  Set connConnection = Nothing
'End Sub %>
 
<%
Dim RsImageFeatured__MMColParam
RsImageFeatured__MMColParam = "393"
If (Request.QueryString("ProdID") <> "") Then 
  RsImageFeatured__MMColParam = Request.QueryString("ProdID")
End If
%>
<%
Dim RsImageFeatured
Dim RsImageFeatured_cmd
Dim RsImageFeatured_numRows
 
Set RsImageFeatured_cmd = Server.CreateObject ("ADODB.Command")
RsImageFeatured_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsImageFeatured_cmd.CommandText = "SELECT tblProducts.ProdName, tblImages.Image FROM tblProducts LEFT JOIN tblImages ON tblProducts.ProdID = tblImages.ProdID WHERE (((tblImages.Featured)=True) AND ((tblProducts.ProdID)= ? )) GROUP BY tblProducts.ProdName, tblImages.Image" 
RsImageFeatured_cmd.Prepared = true
RsImageFeatured_cmd.Parameters.Append RsImageFeatured_cmd.CreateParameter("param1", 5, 1, -1, RsImageFeatured__MMColParam) ' adDouble
 
Set RsImageFeatured = RsImageFeatured_cmd.Execute
RsImageFeatured_numRows = 0
%>
<%
Dim RsImages__MMColParam
RsImages__MMColParam = "393"
If (Request.QueryString("ProdID")  <> "") Then 
  RsImages__MMColParam = Request.QueryString("ProdID") 
End If
%>
<%
Dim RsImages
Dim RsImages_cmd
Dim RsImages_numRows
 
Set RsImages_cmd = Server.CreateObject ("ADODB.Command")
RsImages_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsImages_cmd.CommandText = "SELECT tblProducts.ProdName, tblImages.Image FROM tblProducts LEFT JOIN tblImages ON tblProducts.ProdID = tblImages.ProdID WHERE (((tblImages.Featured)=False) AND ((tblProducts.ProdID)= ? )) GROUP BY tblProducts.ProdName, tblImages.Image" 
RsImages_cmd.Prepared = true
RsImages_cmd.Parameters.Append RsImages_cmd.CreateParameter("param1", 5, 1, -1, RsImages__MMColParam) ' adDouble
 
Set RsImages = RsImages_cmd.Execute
RsImages_numRows = 0
%>
<%
Dim RsDetail__MMColParam
RsDetail__MMColParam = "393"
If (Request.QueryString("ProdID")       <> "") Then 
  RsDetail__MMColParam = Request.QueryString("ProdID")      
End If
%>
<%
Dim RsDetail
Dim RsDetail_cmd
Dim RsDetail_numRows
 
Set RsDetail_cmd = Server.CreateObject ("ADODB.Command")
RsDetail_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsDetail_cmd.CommandText = "SELECT tblProducts.ProdName, tblProducts.ProdLongDesc, tblAvailColours.AvailColourName, tblSizeGroup.SizeName, tblPrice.Price, tblPrice.PriceDiscMin, tblPrice.PriceDiscPrice, tblStock.Quantity, tblSizeGroup.SizeGroupID, tblAvailColours.AvailColourID, tblPrice.PriceID, tblProducts.ProdID, tblProducts.ProdShortDesc FROM ((tblProducts LEFT JOIN (tblSizeGroup RIGHT JOIN (tblStock LEFT JOIN tblPrice ON tblStock.StockProdID = tblPrice.PriceProdID) ON tblSizeGroup.SizeGroupID = tblPrice.PriceSizeID) ON tblProducts.ProdID = tblStock.StockProdID) LEFT JOIN tblImages ON tblProducts.ProdID = tblImages.ProdID) LEFT JOIN (tblAvailColours RIGHT JOIN tblProdColours ON tblAvailColours.AvailColourID = tblProdColours.ProdAvailColour) ON tblProducts.ProdID = tblProdColours.ProdProdID WHERE (((tblProducts.ProdID)= ? )) GROUP BY tblProducts.ProdName, tblProducts.ProdLongDesc, tblAvailColours.AvailColourName, tblSizeGroup.SizeName, tblPrice.Price, tblPrice.PriceDiscMin, tblPrice.PriceDiscPrice, tblStock.Quantity, tblSizeGroup.SizeGroupID, tblAvailColours.AvailColourID, tblPrice.PriceID, tblProducts.ProdID, tblProducts.ProdShortDesc" 
RsDetail_cmd.Prepared = true
RsDetail_cmd.Parameters.Append RsDetail_cmd.CreateParameter("param1", 5, 1, -1, RsDetail__MMColParam) ' adDouble
 
Set RsDetail = RsDetail_cmd.Execute
RsDetail_numRows = 0
%>
<%
Dim RsColour__MMColParam
RsColour__MMColParam = "392"
If (Request.QueryString("ProdID")      <> "") Then 
  RsColour__MMColParam = Request.QueryString("ProdID")     
End If
%>
<%
Dim RsColour
Dim RsColour_cmd
Dim RsColour_numRows
 
Set RsColour_cmd = Server.CreateObject ("ADODB.Command")
RsColour_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsColour_cmd.CommandText = "SELECT Count(tblProdColours.ProdAvailColour) AS CountOfProdAvailColour FROM tblProducts INNER JOIN (tblAvailColours INNER JOIN tblProdColours ON tblAvailColours.AvailColourID = tblProdColours.ProdAvailColour) ON tblProducts.ProdID = tblProdColours.ProdProdID WHERE (((tblProdColours.ProdProdID)= ?))" 
RsColour_cmd.Prepared = true
RsColour_cmd.Parameters.Append RsColour_cmd.CreateParameter("param1", 5, 1, -1, RsColour__MMColParam) ' adDouble
 
Set RsColour = RsColour_cmd.Execute
RsColour_numRows = 0
%>
<%
Dim RsColourName__MMColParam
RsColourName__MMColParam = "392"
If (Request.QueryString("ProdID") <> "") Then 
  RsColourName__MMColParam = Request.QueryString("ProdID")
End If
%>
<%
Dim RsColourName
Dim RsColourName_cmd
Dim RsColourName_numRows
 
Set RsColourName_cmd = Server.CreateObject ("ADODB.Command")
RsColourName_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsColourName_cmd.CommandText = "SELECT tblAvailColours.AvailColourName FROM tblProducts INNER JOIN (tblAvailColours INNER JOIN tblProdColours ON tblAvailColours.AvailColourID = tblProdColours.ProdAvailColour) ON tblProducts.ProdID = tblProdColours.ProdProdID WHERE (((tblProdColours.ProdProdID)= ? ))" 
RsColourName_cmd.Prepared = true
RsColourName_cmd.Parameters.Append RsColourName_cmd.CreateParameter("param1", 5, 1, -1, RsColourName__MMColParam) ' adDouble
 
Set RsColourName = RsColourName_cmd.Execute
RsColourName_numRows = 0
%>
 
<%
Dim HLooper1__numRows
HLooper1__numRows = -2
Dim HLooper1__index
HLooper1__index = 0
RsImages_numRows = RsImages_numRows + HLooper1__numRows
%>
<% 'This is where it all kicks off ************************************************************************************** %>
<%
' WA eCart AddToCart
if (cStr(Request.Form("magecart_1_ATC")) <> "" OR cStr(Request.Form("magecart_1_ATC.x")) <> "")     then
%>
<%
 
Dim RsPrice__ParamProdID
RsPrice__ParamProdID = "392"
If (Request.Form("magecart_1_ID_Add") <> "") Then 
  RsPrice__ParamProdID = Request.Form("magecart_1_ID_Add")
End If
%>
<%
Dim RsPrice__ParamSizeName
RsPrice__ParamSizeName = "Age 8"
If (Request.Form("magecart_1_Size_Add") <> "") Then 
  RsPrice__ParamSizeName = Request.Form("magecart_1_Size_Add")
End If
%>
<%
Dim RsPrice
Dim RsPrice_cmd
Dim RsPrice_numRows
 
Set RsPrice_cmd = Server.CreateObject ("ADODB.Command")
RsPrice_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsPrice_cmd.CommandText = "SELECT tblPrice.Price FROM tblSizeGroup RIGHT JOIN tblPrice ON tblSizeGroup.SizeGroupID = tblPrice.PriceSizeID WHERE (((tblPrice.PriceProdID)= ? ) AND ((tblSizeGroup.SizeName)= ?)) GROUP BY tblPrice.Price" 
RsPrice_cmd.Prepared = true
RsPrice_cmd.Parameters.Append RsPrice_cmd.CreateParameter("param1", 5, 1, -1, RsPrice__ParamProdID) ' adDouble
RsPrice_cmd.Parameters.Append RsPrice_cmd.CreateParameter("param2", 200, 1, 255, RsPrice__ParamSizeName) ' adVarChar
 
Set RsPrice = RsPrice_cmd.Execute
RsPrice_numRows = 0
%>
 
<%
Dim RsStock__ParamProdID
RsStock__ParamProdID = "392"
If (Request.Form("magecart_1_ID_Add") <> "") Then 
  RsStock__ParamProdID = Request.Form("magecart_1_ID_Add")
End If
%>
<%
Dim RsStock__ParamColour
RsStock__ParamColour = "Hot Pink"
If (Request.Form("magecart_1_Colour_Add") <> "") Then 
  RsStock__ParamColour = Request.Form("magecart_1_Colour_Add")
End If
%>
<%
Dim RsStock__ParamSize
RsStock__ParamSize = "Age 8"
If (Request.Form("magecart_1_Size_Add") <> "") Then 
  RsStock__ParamSize = Request.Form("magecart_1_Size_Add")
End If
%>
<%
Dim RsStock
Dim RsStock_cmd
Dim RsStock_numRows
 
Set RsStock_cmd = Server.CreateObject ("ADODB.Command")
RsStock_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsStock_cmd.CommandText = "SELECT tblStock.Quantity, tblProducts.ProdName, tblStock.StockID FROM tblProducts RIGHT JOIN ((tblStock LEFT JOIN tblSizeGroup ON tblStock.StockSizeID = tblSizeGroup.SizeGroupID) LEFT JOIN tblAvailColours ON tblStock.StockColourID = tblAvailColours.AvailColourID) ON tblProducts.ProdID = tblStock.StockProdID WHERE (((tblStock.StockProdID)= ? ) AND ([tblAvailColours].[AvailColourName]= ? ) AND ([tblSizegroup].[SizeName]= ? )) GROUP BY tblStock.Quantity, tblProducts.ProdName, tblStock.StockID" 
RsStock_cmd.Prepared = true
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param1", 5, 1, -1, RsStock__ParamProdID) ' adDouble
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param2", 200, 1, 255, RsStock__ParamColour) ' adVarChar
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param3", 200, 1, 255, RsStock__ParamSize) ' adVarChar
 
Set RsStock = RsStock_cmd.Execute
RsStock_numRows = 0
%>
<% Dim OutOfStock 
      OutOfStock = ("out_of_stock.asp?StockID=" &  Server.HTMLEncode (RsStock.Fields.Item("StockID").Value) & "&QtyRequested=" & Server.HTMLEncode(cStr(Request.Form("magecart_1_Quantity_Add"))))
%>
	<% Dim StockLevel
	StockLevel = (RsStock.Fields.Item("Quantity").Value) %>
<% 'This is where The from is processed ************************************************************************************** %>
<%
  ATC_itemID = cStr(Request.Form("magecart_1_ID_Add"))
  ATC_AddIfIn = 0
  ATC_RedirectAfter = "bag.asp"
  ATC_RedirectIfIn  = ""
    ATC_itemName = "" & cStr(Request.Form("magecart_1_Name_Add")) & ""' column binding
    ATC_itemDescription = "" & cStr(Request.Form("magecart_1_Description_Add")) & ""' column binding
    ATC_itemWeight = cDbl("0")' column binding
    ATC_itemQuantity = "" & cStr(Request.Form("magecart_1_Quantity_Add")) & ""' column binding
    ATC_itemPrice = (RsPrice.Fields.Item("Price").Value) ' column binding
    ATC_itemColour = "" & cStr(Request.Form("magecart_1_Colour_Add")) & ""' column binding
    ATC_itemSize = "" & cStr(Request.Form("magecart_1_Size_Add")) & ""' column binding
	ATC_itemStockID = "" & (RsStock.Fields.Item("StockID").Value) & "" ' column binding
	if CInt(Request.Form("magecart_1_Quantity_Add")) > StockLevel then
	Response.Redirect(OutOfStock)
	else  
	if (IsNumeric(ATC_itemQuantity) AND ATC_itemQuantity <> 0)     then
  
	set magecart = magecart_AddToCart(ATC_AddIfIn, ATC_RedirectIfIn, ATC_itemID, ATC_itemName, ATC_itemDescription, ATC_itemWeight, ATC_itemQuantity, ATC_itemPrice, ATC_itemColour, ATC_itemSize, ATC_itemStockID )
  
if (ATC_RedirectAfter <> "" AND magecart_redirStr = "")     then
      magecart_redirStr = ATC_RedirectAfter
    end if
    Session("WAEC_ContinueRedirect") = cStr(Request.ServerVariables("Script_Name"))  & "?" & cStr(Request.QueryString())
  end if
end if
end if
 %>
   
 
 
'<% 
'RsPrice.Close()
'Set RsPrice = Nothing %>
'<%
'RsStock.Close()
'Set RsStock = Nothing
'%>
<%
' WA eCart Redirect
if (magecart_redirStr <> "")     then
  Response.Redirect(magecart_redirStr)
end if
%>
 
<!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"><!-- InstanceBegin template="/Templates/master1.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="magicalrooms.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
 
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
 
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
 
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<!-- InstanceParam name="bag" type="boolean" value="true" --><!-- InstanceParam name="leftNav" type="boolean" value="true" --><!-- InstanceParam name="admin nav" type="boolean" value="false" --><!-- InstanceParam name="site nav" type="boolean" value="true" -->
</head>
<body onload="MM_preloadImages('img/images/wish_list_selected_03.gif','img/images/log_in_selected_03.gif','img/images/register_selected_03.gif','img/images/delivery_selected_03.gif','img/images/locator_selected_03.gif','img/images/help_selected_03.gif','img/images/voucher_selected_03.gif')">
<div id="container">
   
  <div id="banner">
    <div id="logo"></div>
	<!--#include file="keyword_search.asp" -->
	<div id="tabs"><img src="img/images/full_tabs_03.gif" name="fulltabs" width="467" height="23" border="0" usemap="#tab" id="fulltabs" />
        <map name="tab" id="tab">
          <area shape="rect" coords="2,2,56,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/wish_list_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="58,3,97,21" href="login.asp" onmouseover="MM_swapImage('fulltabs','','img/images/log_in_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="99,3,146,21" href="register.asp" onmouseover="MM_swapImage('fulltabs','','img/images/register_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="149,3,196,23" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/delivery_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="200,3,316,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/locator_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="319,5,350,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/help_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="355,5,455,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/voucher_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
        </map>
    </div>
  </div>
 
  <div id="mainpage">
    <div id="leftnav">
      <script type="text/javascript" language="JavaScript" src="Scripts/drop.js">
	</script>
      
      <!--#include file="nav.asp" -->
      
    <!--#include file="bag_display.asp"-->
    </div>
  <!-- InstanceBeginEditable name="contentarea" --><div id="content">
     
      <div id="detailImages">
        <p><img src="download_detail.asp?id=<%=(RsImageFeatured.Fields.Item("Image").Value)%>&amp;Width=150" alt="<%=(RsImageFeatured.Fields.Item("ProdName").Value)%>" hspace="5" vspace="5" border="0" align="center" />   </p>
        <p> 
        <table>
          <%
startrw = 0
endrw = HLooper1__index
numberColumns = 2
numrows = -1
while((numrows <> 0) AND (Not RsImages.EOF))
	startrw = endrw + 1
	endrw = endrw + numberColumns
 %>
          <tr align="center" valign="top">
            <%
While ((startrw <= endrw) AND (Not RsImages.EOF))
%>
            <td><img src="download_detail_thumbs.asp?id=<%=(RsImages.Fields.Item("Image").Value)%>&amp;Width=70" alt="<%=(RsImages.Fields.Item("ProdName").Value)%>" hspace="5" vspace="5" border="0" align="center" /> </td>
            <%
	startrw = startrw + 1
	RsImages.MoveNext()
	Wend
	%>
          </tr>
          <%
 numrows=numrows-1
 Wend
 %>
        </table>
      </div>
       <div id="detailDetails">
        <br />
<h1><%=(RsDetail.Fields.Item("ProdName").Value)%></h1>
        <p><%=(RsDetail.Fields.Item("ProdLongDesc").Value)%>              </p>
      </div>
       
      <div id="addtobag">
        <p>Choose your required colour and size and select a quantity:</p>
        <form name="magecart_1_ATC_<%=RsDetail.Fields("ProdID").value%>" method="POST" action="<%=cStr(Request.ServerVariables("SCRIPT_NAME"))%><%=WA_eCart_IIf((Request.ServerVariables("QUERY_STRING") <> ""), "?" & Request.ServerVariables("QUERY_STRING"), "")%>">
          <input type="hidden" name="magecart_1_ID_Add" value="<%=(RsDetail.Fields.Item("ProdID").Value)%>" />
          <input type="hidden" name="magecart_1_Name_Add" value="<%=(RsDetail.Fields.Item("ProdName").Value)%>" />
          <input type="hidden" name="magecart_1_Description_Add" value="<%=(RsDetail.Fields.Item("ProdShortDesc").Value)%>" />
          <input type="text" name="magecart_1_Quantity_Add" value="1" size="4" />
<% If (RsColour.Fields.Item("CountOfProdAvailColour").Value)>= 2 Then %>
		     <select name="magecart_1_Colour_Add" id="magecart_1_Colour_Add">
		       <%
While (NOT RsColourName.EOF)
%><option value="<%=(RsColourName.Fields.Item("AvailColourName").Value)%>"><%=(RsColourName.Fields.Item("AvailColourName").Value)%></option><%
  RsColourName.MoveNext()
Wend
If (RsColourName.CursorType > 0) Then
  RsColourName.MoveFirst
Else
  RsColourName.Requery
End If
%>
</select>
	<% Else %>
	<input name="magecart_1_Colour_Add" type="hidden" value="<%=(RsDetail.Fields.Item("AvailColourName").Value)%>" />
	<% End If %>
	<% If Not(RsDetail.Fields.Item("SizeName").Value) = "None" Then %>
		          <select name="magecart_1_Size_Add" id="magecart_1_Size_Add">
             <%
While (NOT RsDetail.EOF)
%>
             <option value="<%=(RsDetail.Fields.Item("SizeName").Value)%>"><%=(RsDetail.Fields.Item("SizeName").Value)%></option>
             <%
  RsDetail.MoveNext()
Wend
If (RsDetail.CursorType > 0) Then
  RsDetail.MoveFirst
Else
  RsDetail.Requery
End If
%>
</select>
	<% Else %>
	<input name="magecart_1_Size_Add" type="hidden" value="<%=(RsDetail.Fields.Item("SizeName").Value)%>" />
	<% End If %>
          <input type="image" src="WA_eCart/Images/Pacifica/Btn2_EN_addtocart.gif" border="0" value="Add to Cart" name="magecart_1_ATC">
        </form>
        <p><br />
        </p>
      </div>
      <br />
      </p>
      
  </div>
    <!-- InstanceEndEditable --></div>
<div class="footer" id="footer"><a href="page.html">How To Find Us</a>  <a href="page.html">Terms  &amp; Conditions</a>  - <a href="page.html">Privacy
  Policy</a> - Returns - Links - Customer Feedback<br />
  &copy; Copyright Magical Rooms 2007</div>
</div></body>
<!-- InstanceEnd --></html>
 
<% 'dbCleanUp() %>
 
<%
RsImageFeatured.Close()
Set RsImageFeatured = Nothing
%>
<%
RsImages.Close()
Set RsImages = Nothing
%>
<%
RsDetail.Close()
Set RsDetail = Nothing
%>
<%
RsColour.Close()
Set RsColour = Nothing
%>
<%
RsColourName.Close()
Set RsColourName = Nothing
%>
'<%
'RsPrice.Close()
'Set RsPrice = Nothing
'%>
'<%
'RsStock.Close()
'Set RsStock = Nothing
'%>

Open in new window

0
Comment
Question by:swordfishsoup
  • 8
  • 6
  • 2
16 Comments
 
LVL 9

Expert Comment

by:CCongdon
ID: 20300294
Hmmm, you might want to consider moving all of your out of stock behaviors to higher up the page so it isn't opening recordsets left and right if its just going to transfer out of the page anyways.

Hmmm, line 201 appears to be the line I just helped you with. Heh. Well, at least I don't think that one is my fault since I just had you add a form field to it and not a recordset value.

Are you sure your 3 form fields (magecart_1_Colour_Add, magecart_1_Size_Add, and magecart_1_ID_Add) are all coming through? And if not, is there a product that meets the default critera of 392/Hot Pink/Age 8? Or what you could be getting is a mix of default data and real data if one of your fields is missing...

0
 

Author Comment

by:swordfishsoup
ID: 20300361
Hi..('m impressed, that was quick)

Nope definately not your fault. if there is a value of at least one in the stock table the page works. It's just if the stock level is at zero.

As to moving the stock behaviours up...don't they HAVE to come after the form action happens to get the form variables - to get the stock ID and quantity...if you see what I mean?
After this >
if (cStr(Request.Form("magecart_1_ATC")) <> "" OR cStr(Request.Form("magecart_1_ATC.x")) <> "")     then

Is there something I should do to this to make it happier with a zero?
<% Dim StockLevel
      StockLevel = (RsStock.Fields.Item("Quantity").Value) %>
<%

Thanks for your time on this. (I've been at this page since 7 am so I'm just going to walk round the block via the pub for half an hour, if I don't reply straight away)

If it helps there is a screen shot of the relationships of the db here: http://www.discburner.co.uk/relationships.html

Dave
0
 
LVL 18

Expert Comment

by:mdougan
ID: 20300521
It is pretty simple, if there are no items in stock, then your recordset will not return any rows, not even a zero count.  So, all you have to do is check for an empty recordset.

<% Dim StockLevel
      if RsStock.BOF or RsStock.EOF Then
         StockLevel = 0
       Else
         StockLevel = (RsStock.Fields.Item("Quantity").Value)
      End if

%>

If you want to do something different when you are completely out of stock, then whever that is, you'll just need to check for a StockLevel of 0.

Also, be aware that any recordset might return BOF or EOF, so, you should always check those flags before ever attempting to reference a field value from any row in the recordset, otherwise you'll get that same error.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 18

Expert Comment

by:mdougan
ID: 20300732
By the way, if you run your query as written in the database itself, you will probably see that no rows are returned for whatever your test product/size group/color was.  If you rewrite the query as below, then you will always get a row of data, as long as the product exists in the product table (I assume all products exist in the product table whether they are in stock or not).

SELECT
   tblStock.Quantity,
   tblProducts.ProdName,
   tblStock.StockID
FROM tblProducts
LEFT OUTER JOIN tblStock ON tblProducts.ProdID = tblStock.StockProdID
LEFT OUTER JOIN tblSizeGroup ON tblStock.StockSizeID = tblSizeGroup.SizeGroupID
LEFT OUTER JOIN tblAvailColours ON tblStock.StockColourID = tblAvailColours.AvailColourID
WHERE (tblProducts.ProdID= ? ) AND ([tblAvailColours].[AvailColourName]= ? ) AND ([tblSizegroup].[SizeName]= ? ) GROUP BY tblStock.Quantity, tblProducts.ProdName, tblStock.StockID

However, the Quantity field will be NULL if there are no items in the Stock table.  So, you should have the appropriate null replacement code.  Can't remember the Access syntax, but in SQL Server it would be

SELECT
   IsNull(tblStock.Quantity, 0) as Quantity,

Or, maybe you need an IIF statement for Access, not really sure.

Because you are referencing the left join parameters in the Where Clause, it is possible that even after changing the query to the one above, you still might not get any rows.  If I were writing this in SQL Server I'd put the parameters for the LEFT JOIN tables up in the JOIN Statement... but doing so would probably change the order of your parameter list.

SELECT
   tblStock.Quantity,
   tblProducts.ProdName,
   tblStock.StockID
FROM tblProducts
LEFT OUTER JOIN tblStock ON tblProducts.ProdID = tblStock.StockProdID
LEFT OUTER JOIN tblSizeGroup ON tblStock.StockSizeID = tblSizeGroup.SizeGroupID
AND ([tblSizegroup].[SizeName]= ? )
LEFT OUTER JOIN tblAvailColours ON tblStock.StockColourID = tblAvailColours.AvailColourID
 AND ([tblAvailColours].[AvailColourName]= ? )
WHERE (tblProducts.ProdID= ? )
GROUP BY tblStock.Quantity, tblProducts.ProdName, tblStock.StockID

I don't know if Access will allow you to reference parameter values in the Join statement though.

0
 
LVL 9

Expert Comment

by:CCongdon
ID: 20300736
The problem is in this record set really:

<%
Dim RsStock
Dim RsStock_cmd
Dim RsStock_numRows
 
Set RsStock_cmd = Server.CreateObject ("ADODB.Command")
RsStock_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsStock_cmd.CommandText = "SELECT tblStock.Quantity, tblProducts.ProdName, tblStock.StockID FROM tblProducts RIGHT JOIN ((tblStock LEFT JOIN tblSizeGroup ON tblStock.StockSizeID = tblSizeGroup.SizeGroupID) LEFT JOIN tblAvailColours ON tblStock.StockColourID = tblAvailColours.AvailColourID) ON tblProducts.ProdID = tblStock.StockProdID WHERE (((tblStock.StockProdID)= ? ) AND ([tblAvailColours].[AvailColourName]= ? ) AND ([tblSizegroup].[SizeName]= ? )) GROUP BY tblStock.Quantity, tblProducts.ProdName, tblStock.StockID"
RsStock_cmd.Prepared = true
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param1", 5, 1, -1, RsStock__ParamProdID) ' adDouble
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param2", 200, 1, 255, RsStock__ParamColour) ' adVarChar
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param3", 200, 1, 255, RsStock__ParamSize) ' adVarChar
 
Set RsStock = RsStock_cmd.Execute
RsStock_numRows = 0
%>

What I'm not sure I understand is why this recordset doesn't load up when Quantity = 0. There is nothing about Quantity in the WHERE clause so that leaves the GROUP BY clause. Is there a good reason for that GROUP BY or can you remove the GROUP BY and the page still works?
0
 

Author Comment

by:swordfishsoup
ID: 20300817
Thanks both for this input.

I've tried the
<% Dim StockLevel
      if RsStock.BOF or RsStock.EOF Then
         StockLevel = 0
       Else
         StockLevel = (RsStock.Fields.Item("Quantity").Value)
      End if

%>


no joy.

And removing the 'group by' doesn't happen either.

I'll get stuck into the rewritten query with null replacement....unless there are any other suggestions?

Thanks again

Dave
0
 

Author Comment

by:swordfishsoup
ID: 20300870
>>>>>>>By the way, if you run your query as written in the database itself, you will probably see that no rows are returned for whatever your test product/size group/color was.  

I've just run the query in Access using the stock ID for the product where I set the stock quantity to zero (for testing) and it does return a result, with all the details for the product and quantity as 0.........

Just thought I'd mention it

0
 

Author Comment

by:swordfishsoup
ID: 20300885
Oh

But when I test it in DW using that stock ID no thing comes bacjk....doh!
0
 
LVL 18

Expert Comment

by:mdougan
ID: 20301011
Curious that it comes back with a result in the database... I know it has to come back with no results in your script code because that is the meaning of your error message.  BOF stands for Beginning Of File and EOF stands for End of File.  They mean that your recordset is positioned Before the First Record or after the Last Record respectively.  If you have no records in your recordset, then they will probably both be true.   If either one of those is true, and you try to reference a field value, you will get that error because you are not positioned on a valid row of data.

So, be carefull in your script that you wrap any field references in an IF statement so that you'll never try to execute that code if BOF or EOF is true.
0
 

Author Comment

by:swordfishsoup
ID: 20301051
Thanks...I think I understand....

Maybe I'm a bit delirious after a long day at this but I'm wondering if a way round woudl be to have two recordsets. the first gets all the info except the quantity (ie stockID etc) and the the second gets the quantity (based on the Stock ID from the first) and if no results are returned redirects...

Does that make any sense at all? or should I just go to bed and get a proper job in the morning!

Dave :)
0
 
LVL 18

Expert Comment

by:mdougan
ID: 20301155
Can you clarify "no joy"?  As I said, you will get that error if you let the code fall through to any recordset field value reference... so, down on line 218, you're referencing a field value... you have to keep the code from falling through to that line if BOF or EOF are true...   maybe doing the redirect immediately is the better choice.

<% Dim StockLevel
      if ((RsStock.BOF = True) or (RsStock.EOF = True)) Then
         Response.Redirect(OutOfStock)
       Else
         StockLevel = (RsStock.Fields.Item("Quantity").Value)
      End if

%>

In any event, I think it is much safer to "drive" the query from the Product table instead of the Stock table.
0
 

Author Comment

by:swordfishsoup
ID: 20302292
>>> Can you clarify "no joy"?
Yeah using this:

<% Dim StockLevel
      if RsStock.BOF or RsStock.EOF Then
         StockLevel = 0
       Else
         StockLevel = (RsStock.Fields.Item("Quantity").Value)


      End if

%>

ither BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/MR07 OffLine/detail.asp, line 226

Maybe it's wehere I'm plkacing it in the code: so here it is again.....
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="WA_eCart/WA_eCart_Definition_VB.asp" -->
<!--#include file="WA_eCart/magecart_VB.asp" -->
<!--#include file="Connections/MagicalRooms.asp" -->
<% 'Sub dbCleanUp()
'  RsPrice.Close()
'  RsStock.Close()
'  connConnection.Close()
'  Set RsPrice = Nothing
'  Set RsStock = Nothing
'  Set connConnection = Nothing
'End Sub %>
 
<%
Dim RsImageFeatured__MMColParam
RsImageFeatured__MMColParam = "393"
If (Request.QueryString("ProdID") <> "") Then 
  RsImageFeatured__MMColParam = Request.QueryString("ProdID")
End If
%>
<%
Dim RsImageFeatured
Dim RsImageFeatured_cmd
Dim RsImageFeatured_numRows
 
Set RsImageFeatured_cmd = Server.CreateObject ("ADODB.Command")
RsImageFeatured_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsImageFeatured_cmd.CommandText = "SELECT tblProducts.ProdName, tblImages.Image FROM tblProducts LEFT JOIN tblImages ON tblProducts.ProdID = tblImages.ProdID WHERE (((tblImages.Featured)=True) AND ((tblProducts.ProdID)= ? )) GROUP BY tblProducts.ProdName, tblImages.Image" 
RsImageFeatured_cmd.Prepared = true
RsImageFeatured_cmd.Parameters.Append RsImageFeatured_cmd.CreateParameter("param1", 5, 1, -1, RsImageFeatured__MMColParam) ' adDouble
 
Set RsImageFeatured = RsImageFeatured_cmd.Execute
RsImageFeatured_numRows = 0
%>
<%
Dim RsImages__MMColParam
RsImages__MMColParam = "393"
If (Request.QueryString("ProdID")  <> "") Then 
  RsImages__MMColParam = Request.QueryString("ProdID") 
End If
%>
<%
Dim RsImages
Dim RsImages_cmd
Dim RsImages_numRows
 
Set RsImages_cmd = Server.CreateObject ("ADODB.Command")
RsImages_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsImages_cmd.CommandText = "SELECT tblProducts.ProdName, tblImages.Image FROM tblProducts LEFT JOIN tblImages ON tblProducts.ProdID = tblImages.ProdID WHERE (((tblImages.Featured)=False) AND ((tblProducts.ProdID)= ? )) GROUP BY tblProducts.ProdName, tblImages.Image" 
RsImages_cmd.Prepared = true
RsImages_cmd.Parameters.Append RsImages_cmd.CreateParameter("param1", 5, 1, -1, RsImages__MMColParam) ' adDouble
 
Set RsImages = RsImages_cmd.Execute
RsImages_numRows = 0
%>
<%
Dim RsDetail__MMColParam
RsDetail__MMColParam = "393"
If (Request.QueryString("ProdID")       <> "") Then 
  RsDetail__MMColParam = Request.QueryString("ProdID")      
End If
%>
<%
Dim RsDetail
Dim RsDetail_cmd
Dim RsDetail_numRows
 
Set RsDetail_cmd = Server.CreateObject ("ADODB.Command")
RsDetail_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsDetail_cmd.CommandText = "SELECT tblProducts.ProdName, tblProducts.ProdLongDesc, tblAvailColours.AvailColourName, tblSizeGroup.SizeName, tblPrice.Price, tblPrice.PriceDiscMin, tblPrice.PriceDiscPrice, tblStock.Quantity, tblSizeGroup.SizeGroupID, tblAvailColours.AvailColourID, tblPrice.PriceID, tblProducts.ProdID, tblProducts.ProdShortDesc FROM ((tblProducts LEFT JOIN (tblSizeGroup RIGHT JOIN (tblStock LEFT JOIN tblPrice ON tblStock.StockProdID = tblPrice.PriceProdID) ON tblSizeGroup.SizeGroupID = tblPrice.PriceSizeID) ON tblProducts.ProdID = tblStock.StockProdID) LEFT JOIN tblImages ON tblProducts.ProdID = tblImages.ProdID) LEFT JOIN (tblAvailColours RIGHT JOIN tblProdColours ON tblAvailColours.AvailColourID = tblProdColours.ProdAvailColour) ON tblProducts.ProdID = tblProdColours.ProdProdID WHERE (((tblProducts.ProdID)= ? )) GROUP BY tblProducts.ProdName, tblProducts.ProdLongDesc, tblAvailColours.AvailColourName, tblSizeGroup.SizeName, tblPrice.Price, tblPrice.PriceDiscMin, tblPrice.PriceDiscPrice, tblStock.Quantity, tblSizeGroup.SizeGroupID, tblAvailColours.AvailColourID, tblPrice.PriceID, tblProducts.ProdID, tblProducts.ProdShortDesc" 
RsDetail_cmd.Prepared = true
RsDetail_cmd.Parameters.Append RsDetail_cmd.CreateParameter("param1", 5, 1, -1, RsDetail__MMColParam) ' adDouble
 
Set RsDetail = RsDetail_cmd.Execute
RsDetail_numRows = 0
%>
<%
Dim RsColour__MMColParam
RsColour__MMColParam = "392"
If (Request.QueryString("ProdID")      <> "") Then 
  RsColour__MMColParam = Request.QueryString("ProdID")     
End If
%>
<%
Dim RsColour
Dim RsColour_cmd
Dim RsColour_numRows
 
Set RsColour_cmd = Server.CreateObject ("ADODB.Command")
RsColour_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsColour_cmd.CommandText = "SELECT Count(tblProdColours.ProdAvailColour) AS CountOfProdAvailColour FROM tblProducts INNER JOIN (tblAvailColours INNER JOIN tblProdColours ON tblAvailColours.AvailColourID = tblProdColours.ProdAvailColour) ON tblProducts.ProdID = tblProdColours.ProdProdID WHERE (((tblProdColours.ProdProdID)= ?))" 
RsColour_cmd.Prepared = true
RsColour_cmd.Parameters.Append RsColour_cmd.CreateParameter("param1", 5, 1, -1, RsColour__MMColParam) ' adDouble
 
Set RsColour = RsColour_cmd.Execute
RsColour_numRows = 0
%>
<%
Dim RsColourName__MMColParam
RsColourName__MMColParam = "392"
If (Request.QueryString("ProdID") <> "") Then 
  RsColourName__MMColParam = Request.QueryString("ProdID")
End If
%>
<%
Dim RsColourName
Dim RsColourName_cmd
Dim RsColourName_numRows
 
Set RsColourName_cmd = Server.CreateObject ("ADODB.Command")
RsColourName_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsColourName_cmd.CommandText = "SELECT tblAvailColours.AvailColourName FROM tblProducts INNER JOIN (tblAvailColours INNER JOIN tblProdColours ON tblAvailColours.AvailColourID = tblProdColours.ProdAvailColour) ON tblProducts.ProdID = tblProdColours.ProdProdID WHERE (((tblProdColours.ProdProdID)= ? ))" 
RsColourName_cmd.Prepared = true
RsColourName_cmd.Parameters.Append RsColourName_cmd.CreateParameter("param1", 5, 1, -1, RsColourName__MMColParam) ' adDouble
 
Set RsColourName = RsColourName_cmd.Execute
RsColourName_numRows = 0
%>
 
<%
Dim HLooper1__numRows
HLooper1__numRows = -2
Dim HLooper1__index
HLooper1__index = 0
RsImages_numRows = RsImages_numRows + HLooper1__numRows
%>
<% 'This is where it all kicks off ************************************************************************************** %>
<%
' WA eCart AddToCart
if (cStr(Request.Form("magecart_1_ATC")) <> "" OR cStr(Request.Form("magecart_1_ATC.x")) <> "")     then
%>
<%
 
Dim RsPrice__ParamProdID
RsPrice__ParamProdID = "392"
If (Request.Form("magecart_1_ID_Add") <> "") Then 
  RsPrice__ParamProdID = Request.Form("magecart_1_ID_Add")
End If
%>
<%
Dim RsPrice__ParamSizeName
RsPrice__ParamSizeName = "Age 8"
If (Request.Form("magecart_1_Size_Add") <> "") Then 
  RsPrice__ParamSizeName = Request.Form("magecart_1_Size_Add")
End If
%>
<%
Dim RsPrice
Dim RsPrice_cmd
Dim RsPrice_numRows
 
Set RsPrice_cmd = Server.CreateObject ("ADODB.Command")
RsPrice_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsPrice_cmd.CommandText = "SELECT tblPrice.Price FROM tblSizeGroup RIGHT JOIN tblPrice ON tblSizeGroup.SizeGroupID = tblPrice.PriceSizeID WHERE (((tblPrice.PriceProdID)= ? ) AND ((tblSizeGroup.SizeName)= ?)) GROUP BY tblPrice.Price" 
RsPrice_cmd.Prepared = true
RsPrice_cmd.Parameters.Append RsPrice_cmd.CreateParameter("param1", 5, 1, -1, RsPrice__ParamProdID) ' adDouble
RsPrice_cmd.Parameters.Append RsPrice_cmd.CreateParameter("param2", 200, 1, 255, RsPrice__ParamSizeName) ' adVarChar
 
Set RsPrice = RsPrice_cmd.Execute
RsPrice_numRows = 0
%>
 
<%
Dim RsStock__ParamProdID
RsStock__ParamProdID = "392"
If (Request.Form("magecart_1_ID_Add") <> "") Then 
  RsStock__ParamProdID = Request.Form("magecart_1_ID_Add")
End If
%>
<%
Dim RsStock__ParamColour
RsStock__ParamColour = "Hot Pink"
If (Request.Form("magecart_1_Colour_Add") <> "") Then 
  RsStock__ParamColour = Request.Form("magecart_1_Colour_Add")
End If
%>
<%
Dim RsStock__ParamSize
RsStock__ParamSize = "Age 8"
If (Request.Form("magecart_1_Size_Add") <> "") Then 
  RsStock__ParamSize = Request.Form("magecart_1_Size_Add")
End If
%>
 
<%
Dim RsStock
Dim RsStock_cmd
Dim RsStock_numRows
 
Set RsStock_cmd = Server.CreateObject ("ADODB.Command")
RsStock_cmd.ActiveConnection = MM_MagicalRooms_STRING
RsStock_cmd.CommandText = "SELECT tblStock.Quantity, tblProducts.ProdName, tblStock.StockID FROM tblProducts RIGHT JOIN ((tblStock LEFT JOIN tblSizeGroup ON tblStock.StockSizeID = tblSizeGroup.SizeGroupID) LEFT JOIN tblAvailColours ON tblStock.StockColourID = tblAvailColours.AvailColourID) ON tblProducts.ProdID = tblStock.StockProdID WHERE (((tblStock.StockProdID)= ? ) AND ([tblAvailColours].[AvailColourName]= ? ) AND ([tblSizegroup].[SizeName]= ? )) GROUP BY tblStock.Quantity, tblProducts.ProdName, tblStock.StockID" 
RsStock_cmd.Prepared = true
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param1", 5, 1, -1, RsStock__ParamProdID) ' adDouble
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param2", 200, 1, 255, RsStock__ParamColour) ' adVarChar
RsStock_cmd.Parameters.Append RsStock_cmd.CreateParameter("param3", 200, 1, 255, RsStock__ParamSize) ' adVarChar
 
Set RsStock = RsStock_cmd.Execute
RsStock_numRows = 0
%>
<% Dim StockLevel
      if RsStock.BOF or RsStock.EOF Then
         StockLevel = 0
       Else
         StockLevel = (RsStock.Fields.Item("Quantity").Value) 
      End if
 
%>
 
 
	'<% 'Dim StockLevel
'	StockLevel = (RsStock.Fields.Item("Quantity").Value) %>
<% 'This is where The from is processed ************************************************************************************** %>
<%
  ATC_itemID = cStr(Request.Form("magecart_1_ID_Add"))
  ATC_AddIfIn = 0
  ATC_RedirectAfter = "bag.asp"
  ATC_RedirectIfIn  = ""
    ATC_itemName = "" & cStr(Request.Form("magecart_1_Name_Add")) & ""' column binding
    ATC_itemDescription = "" & cStr(Request.Form("magecart_1_Description_Add")) & ""' column binding
    ATC_itemWeight = cDbl("0")' column binding
    ATC_itemQuantity = "" & cStr(Request.Form("magecart_1_Quantity_Add")) & ""' column binding
    ATC_itemPrice = (RsPrice.Fields.Item("Price").Value) ' column binding
    ATC_itemColour = "" & cStr(Request.Form("magecart_1_Colour_Add")) & ""' column binding
    ATC_itemSize = "" & cStr(Request.Form("magecart_1_Size_Add")) & ""' column binding
	ATC_itemStockID = "" & (RsStock.Fields.Item("StockID").Value) & "" ' column binding
	if CInt(Request.Form("magecart_1_Quantity_Add")) > StockLevel then %>
	<% Dim OutOfStock 
      OutOfStock = ("out_of_stock.asp?StockID=" &  Server.HTMLEncode (RsStock.Fields.Item("StockID").Value) & "&QtyRequested=" & Server.HTMLEncode(cStr(Request.Form("magecart_1_Quantity_Add"))))
%>
<%Response.Redirect(OutOfStock)
	else  
	if (IsNumeric(ATC_itemQuantity) AND ATC_itemQuantity <> 0)     then
  
	set magecart = magecart_AddToCart(ATC_AddIfIn, ATC_RedirectIfIn, ATC_itemID, ATC_itemName, ATC_itemDescription, ATC_itemWeight, ATC_itemQuantity, ATC_itemPrice, ATC_itemColour, ATC_itemSize, ATC_itemStockID )
  
if (ATC_RedirectAfter <> "" AND magecart_redirStr = "")     then
      magecart_redirStr = ATC_RedirectAfter
    end if
    Session("WAEC_ContinueRedirect") = cStr(Request.ServerVariables("Script_Name"))  & "?" & cStr(Request.QueryString())
  end if
end if
end if
 %>
   
 
 
'<% 
'RsPrice.Close()
'Set RsPrice = Nothing %>
'<%
'RsStock.Close()
'Set RsStock = Nothing
'%>
<%
' WA eCart Redirect
if (magecart_redirStr <> "")     then
  Response.Redirect(magecart_redirStr)
end if
%>
 
<!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"><!-- InstanceBegin template="/Templates/master1.dwt.asp" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="magicalrooms.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
 
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
 
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
 
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<!-- InstanceParam name="bag" type="boolean" value="true" --><!-- InstanceParam name="leftNav" type="boolean" value="true" --><!-- InstanceParam name="admin nav" type="boolean" value="false" --><!-- InstanceParam name="site nav" type="boolean" value="true" -->
</head>
<body onload="MM_preloadImages('img/images/wish_list_selected_03.gif','img/images/log_in_selected_03.gif','img/images/register_selected_03.gif','img/images/delivery_selected_03.gif','img/images/locator_selected_03.gif','img/images/help_selected_03.gif','img/images/voucher_selected_03.gif')">
<div id="container">
   
  <div id="banner">
    <div id="logo"></div>
	<!--#include file="keyword_search.asp" -->
	<div id="tabs"><img src="img/images/full_tabs_03.gif" name="fulltabs" width="467" height="23" border="0" usemap="#tab" id="fulltabs" />
        <map name="tab" id="tab">
          <area shape="rect" coords="2,2,56,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/wish_list_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="58,3,97,21" href="login.asp" onmouseover="MM_swapImage('fulltabs','','img/images/log_in_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="99,3,146,21" href="register.asp" onmouseover="MM_swapImage('fulltabs','','img/images/register_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="149,3,196,23" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/delivery_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="200,3,316,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/locator_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="319,5,350,22" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/help_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
          <area shape="rect" coords="355,5,455,21" href="#" onmouseover="MM_swapImage('fulltabs','','img/images/voucher_selected_03.gif',1)" onmouseout="MM_swapImgRestore()" />
        </map>
    </div>
  </div>
 
  <div id="mainpage">
    <div id="leftnav">
      <script type="text/javascript" language="JavaScript" src="Scripts/drop.js">
	</script>
      
      <!--#include file="nav.asp" -->
      
    <!--#include file="bag_display.asp"-->
    </div>
  <!-- InstanceBeginEditable name="contentarea" --><div id="content">
     
      <div id="detailImages">
        <p><img src="download_detail.asp?id=<%=(RsImageFeatured.Fields.Item("Image").Value)%>&amp;Width=150" alt="<%=(RsImageFeatured.Fields.Item("ProdName").Value)%>" hspace="5" vspace="5" border="0" align="center" />   </p>
        <p> 
        <table>
          <%
startrw = 0
endrw = HLooper1__index
numberColumns = 2
numrows = -1
while((numrows <> 0) AND (Not RsImages.EOF))
	startrw = endrw + 1
	endrw = endrw + numberColumns
 %>
          <tr align="center" valign="top">
            <%
While ((startrw <= endrw) AND (Not RsImages.EOF))
%>
            <td><img src="download_detail_thumbs.asp?id=<%=(RsImages.Fields.Item("Image").Value)%>&amp;Width=70" alt="<%=(RsImages.Fields.Item("ProdName").Value)%>" hspace="5" vspace="5" border="0" align="center" /> </td>
            <%
	startrw = startrw + 1
	RsImages.MoveNext()
	Wend
	%>
          </tr>
          <%
 numrows=numrows-1
 Wend
 %>
        </table>
      </div>
       <div id="detailDetails">
        <br />
<h1><%=(RsDetail.Fields.Item("ProdName").Value)%></h1>
        <p><%=(RsDetail.Fields.Item("ProdLongDesc").Value)%>              </p>
      </div>
       
      <div id="addtobag">
        <p>Choose your required colour and size and select a quantity:</p>
        <form name="magecart_1_ATC_<%=RsDetail.Fields("ProdID").value%>" method="POST" action="<%=cStr(Request.ServerVariables("SCRIPT_NAME"))%><%=WA_eCart_IIf((Request.ServerVariables("QUERY_STRING") <> ""), "?" & Request.ServerVariables("QUERY_STRING"), "")%>">
          <input type="hidden" name="magecart_1_ID_Add" value="<%=(RsDetail.Fields.Item("ProdID").Value)%>" />
          <input type="hidden" name="magecart_1_Name_Add" value="<%=(RsDetail.Fields.Item("ProdName").Value)%>" />
          <input type="hidden" name="magecart_1_Description_Add" value="<%=(RsDetail.Fields.Item("ProdShortDesc").Value)%>" />
          <input type="text" name="magecart_1_Quantity_Add" value="1" size="4" />
<% If (RsColour.Fields.Item("CountOfProdAvailColour").Value)>= 2 Then %>
		     <select name="magecart_1_Colour_Add" id="magecart_1_Colour_Add">
		       <%
While (NOT RsColourName.EOF)
%><option value="<%=(RsColourName.Fields.Item("AvailColourName").Value)%>"><%=(RsColourName.Fields.Item("AvailColourName").Value)%></option><%
  RsColourName.MoveNext()
Wend
If (RsColourName.CursorType > 0) Then
  RsColourName.MoveFirst
Else
  RsColourName.Requery
End If
%>
</select>
	<% Else %>
	<input name="magecart_1_Colour_Add" type="hidden" value="<%=(RsDetail.Fields.Item("AvailColourName").Value)%>" />
	<% End If %>
	<% If Not(RsDetail.Fields.Item("SizeName").Value) = "None" Then %>
		          <select name="magecart_1_Size_Add" id="magecart_1_Size_Add">
             <%
While (NOT RsDetail.EOF)
%>
             <option value="<%=(RsDetail.Fields.Item("SizeName").Value)%>"><%=(RsDetail.Fields.Item("SizeName").Value)%></option>
             <%
  RsDetail.MoveNext()
Wend
If (RsDetail.CursorType > 0) Then
  RsDetail.MoveFirst
Else
  RsDetail.Requery
End If
%>
</select>
	<% Else %>
	<input name="magecart_1_Size_Add" type="hidden" value="<%=(RsDetail.Fields.Item("SizeName").Value)%>" />
	<% End If %>
          <input type="image" src="WA_eCart/Images/Pacifica/Btn2_EN_addtocart.gif" border="0" value="Add to Cart" name="magecart_1_ATC">
        </form>
        <p><br />
        </p>
      </div>
      <br />
      </p>
      
  </div>
    <!-- InstanceEndEditable --></div>
<div class="footer" id="footer"><a href="page.html">How To Find Us</a>  <a href="page.html">Terms  &amp; Conditions</a>  - <a href="page.html">Privacy
  Policy</a> - Returns - Links - Customer Feedback<br />
  &copy; Copyright Magical Rooms 2007</div>
</div></body>
<!-- InstanceEnd --></html>
 
<% 'dbCleanUp() %>
 
<%
RsImageFeatured.Close()
Set RsImageFeatured = Nothing
%>
<%
RsImages.Close()
Set RsImages = Nothing
%>
<%
RsDetail.Close()
Set RsDetail = Nothing
%>
<%
RsColour.Close()
Set RsColour = Nothing
%>
<%
RsColourName.Close()
Set RsColourName = Nothing
%>
'<%
'RsPrice.Close()
'Set RsPrice = Nothing
'%>
'<%
'RsStock.Close()
'Set RsStock = Nothing
'%>

Open in new window

0
 
LVL 18

Accepted Solution

by:
mdougan earned 500 total points
ID: 20302581
Well, you see that the line that is flagged in the error message is on line 226 which is this line

ATC_itemStockID = "" & (RsStock.Fields.Item("StockID").Value) & "" ' column binding

That line is referencing a field in the RsStock recordset.  However, if RsStock.EOF or RsStock.BOF = True, then trying to access the field StockID will result in the error you are getting.  So, I think you should do the Redirect as I posted in the latest sample (with a few additions).  This replaces the code up around line 201

<% Dim StockLevel
      if ((RsStock.BOF = True) or (RsStock.EOF = True)) Then
         Dim OutOfStock
         'I dont have the Stock ID, so, I'm using the Product ID.. not sure what you can do here
         OutOfStock = ("out_of_stock.asp?StockID=" &  Server.HTMLEncode (cStr(Request.Form("magecart_1_ID_Add"))) & "&QtyRequested=" & Server.HTMLEncode(cStr(Request.Form("magecart_1_Quantity_Add"))))
         Response.Redirect(OutOfStock)
       Else
         StockLevel = (RsStock.Fields.Item("Quantity").Value)
      End if

%>
0
 

Author Comment

by:swordfishsoup
ID: 20303787
Well mdougan....

Early morning points for you!

Thanks that last lead was great. I have adapted it slightly - adding an additional out of stock page/redirect - for items wher stock is zero - I'll adapt this to come up with a list of alternative products and to show other size/colour options of the same product that are available. I guess I could probaly do this on the same out of stock page with something like ' if request query.string = prodid then use this if stock ID use that.......Ill experiment briefly this morning but then will move on. It would be better to do all of this on the one page...but priorities call

I had an issue with the url redirect so as I don't need the stockID if stock is 0 I am just grabbing the ProdID form the initial recordset for the page.

Thanks so much for your time and help.

Have a good weekend (I'll be still doing this.............Got to launch it next week!!!!)

Dave

Adapted code -


<% Dim StockLevel
      if ((RsStock.BOF = True) or (RsStock.EOF = True)) Then
         Dim OutOfStockA 
         'I dont have the Stock ID, so, I'm using the Product ID.. not sure what you can do here
         OutOfStockA = ("out_of_stock2.asp?StockProdID=" &  Server.HTMLEncode (cStr(RsDetail.Fields.Item("ProdID").Value))) 
		  Response.Redirect(OutOfStockA)
       Else
         StockLevel = (RsStock.Fields.Item("Quantity").Value) 
      End if
 
%>
 
	'<% 'Dim StockLevel
'	StockLevel = (RsStock.Fields.Item("Quantity").Value) %>
<% 'This is where The from is processed ************************************************************************************** %>
<%
  ATC_itemID = cStr(Request.Form("magecart_1_ID_Add"))
  ATC_AddIfIn = 0
  ATC_RedirectAfter = "bag.asp"
  ATC_RedirectIfIn  = ""
    ATC_itemName = "" & cStr(Request.Form("magecart_1_Name_Add")) & ""' column binding
    ATC_itemDescription = "" & cStr(Request.Form("magecart_1_Description_Add")) & ""' column binding
    ATC_itemWeight = cDbl("0")' column binding
    ATC_itemQuantity = "" & cStr(Request.Form("magecart_1_Quantity_Add")) & ""' column binding
    ATC_itemPrice = (RsPrice.Fields.Item("Price").Value) ' column binding
    ATC_itemColour = "" & cStr(Request.Form("magecart_1_Colour_Add")) & ""' column binding
    ATC_itemSize = "" & cStr(Request.Form("magecart_1_Size_Add")) & ""' column binding
	ATC_itemStockID = "" & (RsStock.Fields.Item("StockID").Value) & "" ' column binding
	if CInt(Request.Form("magecart_1_Quantity_Add")) > StockLevel then %>
	<% Dim OutOfStockB 
      OutOfStockB = ("out_of_stock.asp?StockID=" &  Server.HTMLEncode (RsStock.Fields.Item("StockID").Value) & "&QtyRequested=" & Server.HTMLEncode(cStr(Request.Form("magecart_1_Quantity_Add"))))
%>
<%Response.Redirect(OutOfStockB)
	else  
	if (IsNumeric(ATC_itemQuantity) AND ATC_itemQuantity <> 0)     then
  
	set magecart = magecart_AddToCart(ATC_AddIfIn, ATC_RedirectIfIn, ATC_itemID, ATC_itemName, ATC_itemDescription, ATC_itemWeight, ATC_itemQuantity, ATC_itemPrice, ATC_itemColour, ATC_itemSize, ATC_itemStockID )
  
if (ATC_RedirectAfter <> "" AND magecart_redirStr = "")     then
      magecart_redirStr = ATC_RedirectAfter
    end if
    Session("WAEC_ContinueRedirect") = cStr(Request.ServerVariables("Script_Name"))  & "?" & cStr(Request.QueryString())
  end if
end if
end if
 %>

Open in new window

0
 

Author Closing Comment

by:swordfishsoup
ID: 31409609
Excellent help, thanks
0
 
LVL 18

Expert Comment

by:mdougan
ID: 20304600
Thanks!  And congratulations, sounds like you are on you are well on your way!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending a email via excel using vba 6 82
Passing a Text Box name to a Sub 6 96
VB6 - Scroll Mouse wheel on Picturebox 13 44
Assigning VBA code to a specific worksheet 3 25
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question