Link to home
Start Free TrialLog in
Avatar of CLSTEAM
CLSTEAM

asked on

ASP and Cookies not showing information.

This web page allows customer to search for a property, after the property is found it will display the products offered at this property.  This is the search page.  I will only post the ASP code as the rest is just HTML formatting for the page:

<!-- #include file="./inc/config.asp" -->
<%
      'address = Request.QueryString("address")
      propertyaccount = Request.QueryString("propertyaccount")
      setaddress = Request.QueryString("setaddress")
      str = ""
      nextitem = Request.QueryString("nextitem")
      derror = ""
      dim regExp
      set regExp = new regexp
      regExp.Pattern = "[^0-9a-zA-Z\ ]"
      regExp.Global = True
      address = regExp.Replace(Request.QueryString("address"), "")
      
      if(address <> "" and setaddress = 0) then
            q = "select * from propertylookup where NameOrAddress like '%" & address & "%'"
            if (nextitem > 1) then
                  q = q & " and PropertyAccount not in (select top " & nextitem & " PropertyAccount from propertylookup where NameOrAddress like '%" & address & "%')"
            else
                  nextitem = 1
            end if
            dbRs.Open q, dbConn, 2, 2
            iRecordCount = 0
            do while not dbRs.EOF
                  iRecordCount = iRecordCount + 1
                  dbRs.MoveNext
            loop
            dbRs.Close
            dbRs.Open q, dbConn, 2, 2
            if (not dbRs.BOF and iRecordCount > 1) then
                  dim d
                  if (nextitem < iRecordCount) then
                        dbRs.MoveNext
                  end if
            end if
            if not (dbRs.BOF and dbRs.EOF) then
                  Set dbRs2 = Server.CreateObject ("ADODB.Recordset")
                  q2 = "select * from PropertyAddresses where PropertyAccount = '" & myunescape(dbRs("PropertyAccount")) & "'"
                  dbRs2.Open q2, dbConn, 2,2
                  iRecordCount = 0
                  do while not dbRs2.EOF
                        iRecordCount = iRecordCount + 1
                        dbRs2.MoveNext
                  loop
                  dbRs2.Close
                  if (iRecordCount > 0) then
                        dbRs2.Open q2, dbConn, 2,2
                        str = "<b>" & myunescape(dbRs2("propertyname")) & ":</b><br>" & vbCrLf & _
                              myunescape(dbRs2("propertyaddress")) & "<br>" & vbCrLf & _
                              myunescape(dbRs2("propertycity")) & ", " & myunescape(dbRs2("propertyzip"))
                        nextitem = nextitem + 1
                        view = 1
                        derror = "Is this your location?"
                        propertyaccount = myunescape(dbRs("PropertyAccount"))
                        dbRs2.Close
                        Set dbRs2 = nothing
                  else
                        derror = "Database error: No records found for " & myunescape(dbRs("PropertyAccount"))
                        view = 1
                        nextitem = nextitem + 1
                  end if
            else
                  nextitem = 1
                  view = 0
                  derror = "<b>Sorry, but the property you are looking for is not in our database</b>"
            end if
            dbRs.Close
            Set dbRs = nothing
      end if
      
      if (setaddress = 1 and isnumeric(propertyaccount)) then
            if (request.Cookies.count > 0) then
                  Response.Cookies("property") = ""
                  Response.Cookies("acct") = ""
                  Response.Cookies("Residence") = ""
                  Response.Cookies("pName") = ""
            end if
            q = "select * from PropertyProductLineInfo where propertyaccount = '" & propertyaccount & "' order by ProductLineSequence"
            dbRs.Open q, dbConn, 2,2
            dbRs.MoveFirst
            x = 1
            Set dbRs2 = Server.CreateObject ("ADODB.Recordset")
            q2 = "select * from PropertyAddresses where propertyaccount = '" & myunescape(dbRs("PropertyAccount")) & "'"
            dbRs2.Open q2, dbConn, 2,2
            pname = myunescape(dbRs2("propertyname"))
            paddress = "<b>" & myunescape(dbRs2("propertyname")) & ":</b><br>" & vbCrLf & _
                  myunescape(dbRs2("propertyaddress")) & "<br>" & vbCrLf & _
                  myunescape(dbRs2("propertycity")) & ", " & myunescape(dbRs2("propertyzip"))
            dbRs2.Close
            Set dbRs2 = nothing
            Response.Cookies("acct") = propertyaccount
            Response.Cookies("Residence") = paddress
            Response.Cookies("pName") = pname
            while not dbRs.EOF
                  Response.Cookies("property")("prod" & x) = myunescape(dbRs("product"))
                  x = x + 1
                  dbRs.MoveNext
            wend
            dbRs.Close
            Response.Redirect("sattv-base-pkgs.asp")
      end if

%>

When the property is found, it wll redirect the browser to the sattv-base-pkgs.asp page which will display the products offered at this property.  This is the code for sattv-base-pkgs.asp:

<!-- #include file="./inc/config.asp" -->
<%
      dim x, y
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
      <title>Consolidated Smart Systems</title>
      <LINK REL="stylesheet" HREF="style.css" TYPE="text/css">
<SCRIPT LANGUAGE="JavaScript" SRC="nav.js"></SCRIPT>
<script language="JavaScript">
strSection="products_services";
strSub="sat_tv";
strSubSub="sattv_base_pkgs";
checkResidence();
</script>
</head>

<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#DAEEF7">
<!--LOGO AND NAV TABLE-->
<table width="760" cellpadding="0" cellspacing="0" border="0">
      <tr>
            <td>
                  <table width="760" cellpadding="0" cellspacing="0" border="0">
                        <tr>
                              <td width="299" valign="top" align="left" rowspan="4"><a href="index.html"><img src="images/logo.gif" width="299" height="130" alt="Consolidated Smart Systems" border="0"></a></td>
                              <td width="461" valign="top" align="left"><img src="images/lines-top.gif" width="281" height="47" alt="" border="0"><!--ABOUT AND CONTACT NAV (IN NAV.JS FILE)--><script language="JavaScript">printAboutContactNav();</script></td>
                        </tr>
                        <tr>
                              <td width="461" valign="top" align="left"><!--PRODUCTS/CUSTOMER CARE NAV (IN NAV.JS FILE)--><script language="JavaScript">printPSCCNav();</script></td>
                        </tr>
                        <tr>
                              <td width="461" valign="top" align="left"><img src="images/lines-middle.gif" width="461" height="22" alt="" border="0"></td>
                        </tr>
                        <tr>
                              <td width="461" valign="top" align="left"><img src="images/lines-bottom.gif" width="461" height="28" alt="" border="0"></td>
                        </tr>
                  </table>
            </td>
      </tr>
</table>
<!--MAIN CONTENT AND RIGHT NAV BOX TABLE-->
<table width="760" cellpadding="0" cellspacing="0" border="0">
      <tr>
            <td valign="top" align="left" width="21" rowspan="2"><img src="images/spacer.gif" width="21" height="1" alt="" border="0"></td>
            <td valign="top" align="left" width="440"><img src="images/header-available-packages.gif" width="440" height="37" alt="FAQS" border="0"></td>
            <td valign="top" align="left" width="24" rowspan="2"><img src="images/spacer.gif" width="24" height="1" alt="" border="0"></td>
            <td valign="top" align="left" width="272" rowspan="2"><!--NAV BOX TABLE--><table width="270" cellpadding="0" cellspacing="0" border="0" style="border: solid #A9CEEE 1px; background-color: #C7DCEB;">
                        <tr>
                              <td valign="top" align="left" width="10" rowspan="2"><img src="images/spacer.gif" width="10" height="1" alt="" border="0"></td>
                              <td valign="top" align="left" width="260" colspan="2"><img src="images/nav-box-sattv-internet.gif" width="260" height="37" alt="" border="0"></td>
                        </tr>
                        <tr>
                              <td valign="top" align="left" width="130" class="nav" ><!--RIGHT NAV BOX LINKS (IN NAV.JS FILE)--><script language="JavaScript">printNavBox();</script></td>
                              <td valign="top" align="left" width="130" class="red-bold"><!--RIGHT NAV BOX SUB LINKS (IN NAV.JS FILE)--><script language="JavaScript">printSubNavBox();</script></td>
                        </tr>
                        <tr>
                              <td valign="top" align="left" colspan="3"><img src="images/spacer.gif" width="1" height="10" alt="" border="0"></td>
                        </tr>
                  </table><!--END NAV BOX-->
                  <br>
                  <!--CURRENT RESIDENCE BOX--><script>printCurrentResidence();</script><!--END CURRENT RESIDENCE BOX-->
                  <br>
                  <!--ENJOY PAY PER VIEW BOX TABLE--><table width="270" cellpadding="0" cellspacing="0" border="0" style="border: solid #A9CEEE 1px; background-color: #EAF6FB;">
                        <tr>
                              <td valign="top" align="left" width="10" rowspan="2"><img src="images/spacer.gif" width="10" height="1" alt="" border="0"></td>
                              <td valign="top" align="left" colspan="2"><img src="images/enjoy-pay-per-view.gif" width="260" height="57" alt="" border="0"></td>
                        </tr>
                        <tr>
                              <td valign="top" align="left"><img src="images/spacer.gif" width="4" height="1" alt="" border="0"></td>
                              <td valign="top" align="left"><img src="images/pic-pay-per-view.jpg" width="243" height="90" alt="" border="0"><p>Many of the country's biggest sporting events and first-run movies are offered via satellite TV. Subscribe to a package or pick and choose the ones you want. It's as easy as 1-2-3!</p></td>
                        </tr>
                        <tr>
                              <td valign="top" align="left" colspan="3"><img src="images/spacer.gif" width="1" height="10" alt="" border="0"></td>
                        </tr>
                  </table><!--END PAY PER VIEW BOX-->
            </td>
            <td valign="top" align="left" width="3" rowspan="2"><img src="images/spacer.gif" width="3" height="1" alt="" border="0"></td>
      </tr>
      <tr>
            <td valign="top" align="left"><span class="red-header">Satellite TV Base Packages:</span>
            <p>These low-cost packages offer great channel line-ups and entertainment for the whole family.</p>
<%
            p = 0
            cat = "base"
            displayall = 1
            for each x in Request.Cookies
            if Request.Cookies(x).HasKeys then
                  for each y in Request.Cookies(x)
                        if y <> "acct" then
                              q = "select * from products where product = '" & Request.Cookies(x)(y) & "'"
                              displayall = 0
                              dbRs.Open q, dbConn, 2, 2
                              if (myunescape(dbRs("category")) = cat) then
                                    p = p + 1
                                    header = myunescape(dbRs("productheader"))
                                    desc = myunescape(dbRs("productparagraph"))
                                    listing = myunescape(dbRs("productlink"))
                                    listing2 = myunescape(dbRs("productlinkname"))
                                    if (dbRs("producthasalink") = true) then
                                          desc = desc & "<br><span class=""red-bold"">&gt;</span><a href=""" & listing & """ class=""red-bold"">" & listing2 & "</a>"
                                    end if
%>
<hr>
<p><b><%=header%></b><br>
<%=desc%>
</p>
<%
                              end if
                              dbRs.Close
                        end if
                  next
            end if
      next
      if (p < 1 and displayall = 0) then
            response.Write("<br><p><b>Sorry, this service is not available at your property.</b></p>")
      end if
      
      if (displayall = 1) then
            q = "select * from products"
            dbRs.Open q, dbConn, 2, 2
            dbRs.MoveFirst
            while not dbRs.EOF
                  if (myunescape(dbRs("category")) = cat) then
                        header = myunescape(dbRs("productheader"))
                        desc = myunescape(dbRs("productparagraph"))
                        listing = myunescape(dbRs("productlink"))
                        listing2 = myunescape(dbRs("productlinkname"))
                        if (dbRs("producthasalink") = true) then
                              desc = desc & "<br><span class=""red-bold"">&gt;</span><a href=""" & listing & """ class=""red-bold"">" & listing2 & "</a>"
                        end if
%>
<hr>
<p><b><%=header%></b><br>
<%=desc%>
</p>
<%
                  end if
                  dbRs.MoveNext
            wend
            dbRs.Close
      end if
%>
</td>
      </tr>
</table>
<br><br>
<!--FOOTER-->
<table width="760" cellpadding="0" cellspacing="0" border="0">
      <tr>
            <td valign="top" align="left" width="21"><img src="images/spacer.gif" width="21" height="1" alt="" border="0"></td>
            <td valign="top" align="left"><script language="JavaScript">printFooter();</script></td>
      </tr>
</table>
<br>
<br>

</body>
</html>

The problem is that no information is currently being displayed after the customer selects a property.  I had this problem before and I found that it was "resolved" by deleting the cookies.  Now that does not work anymore.  IE6, IE7, Firefox and Netscape will not display anything.  Even after I delete the cookies.  Opera however is displaying the information.  Any ideas?  Thanks for any feedback.
Avatar of Badotz
Badotz
Flag of United States of America image

<$.02>
It might be time to abandon cookies and persist the information to the server via Ajax. I can't say it is a better method than cookies (it is), but it *is* supported by IE, FF and Opera.</$.02>
Avatar of CLSTEAM
CLSTEAM

ASKER

@ Badotz:  It's just not possible with this.  I am not the original writer of this code and I don't have the knowledge yet to rewrite it in another language.  I'm barely starting to learn ASP as it is.  Thanks.
>>It's just not possible with this.

Why in the world not?

>>I am not the original writer of this code and I don't have the knowledge yet to rewrite it in another language.

Ajax is a technique, not a language.

<$.02>
If you are unwilling to even investigate a new thing, well, then, perhaps you should be in another line of work?
</$.02>
Ajax is a technique, not a language.

<.02>
Well, having some knowledge of programming languages will certainly help anyone trying to implement AJAX. It still requires some knowledge of Javascript to implement the technique.
</.02>

As for the original problem.... do session variables work and are they a viable solution? (One reason I'm asking is because session variables use cookies also, so if they are working, then the problem lies in your code.)
Avatar of CLSTEAM

ASKER

@ L00M: Session variables do work as I have used them in other projects on this website.  I think that is where I will have to go eventually, I was just hoping I could find a quick fix for the time being.  Thanks.
I think switching to session variables will be fairly painless. Could almost do it with a find/replace.
Avatar of CLSTEAM

ASKER

I think I might have found the problem.  I inserted a few response.write lines to see what the cookies had stored in them and got this as a result:

__utma
__utmb
__utmc
__utmz
118133531.1193687189.1.1.utmccn

Obviously, that is not the info that should be there.  Did a little googling and turns out this cookie is one used by Google Analytics (which the website uses).  So I think the code is reading the google cookie instead of the one the page creates.  How can I tell it to read the cookie that was created by the code rather than the one for Google Analytics?  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of L00M
L00M
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CLSTEAM

ASKER

So close.  I put the code in the page and got the following:

__utma: 118133531.985399988.1193687189.1193687189.1193688817.2__utmb: 118133531__utmz has the following keys:
118133531.1193687189.1.1.utmccn: (direct)|utmcsr=(direct)|utmcmd=(none)
__utmc: 118133531pName: Casa De VidaResidence: Casa De Vida:
3230 Overland Ave.
Los Angeles, 90034acct: 76test has the following keys:
property:
acct: 684
Residence: The Lakes:
3400 Avenue of the Arts
Costa Mesa, 92626
pName: The Lakes
property has the following keys:
prod1: CS36LL
prod8: Premium5
prod11: TCPRW
prod2: CS36 2495
prod9: TCW
prod15: ProInternet
prod3: CS36DTV
prod12: BasicInternet
prod4: Premium1
prod5: Premium2
prod13: PremiumInternet
prod6: Premium3
prod10: TCPW
prod7: Premium4
prod14: UltraInternet
__utma
__utmb
__utmz
118133531.1193687189.1.1.utmccn

So the information that is supposed to be there is there...how do I pull out the required cookie?  Everything beginning from pName down is what I need....Thank you so much.
Avatar of CLSTEAM

ASKER

It looks as if though I have fixed it.  1st the original code:

ORIGINAL:

<%
            p = 0
            cat = "base"
            displayall = 1
            for each x in Request.Cookies
            if Request.Cookies(x).HasKeys then
                  for each y in Request.Cookies(x)
                        if y <> "acct" then
                              q = "select * from products where product = '" & Request.Cookies(x)(y) & "'"
                              displayall = 0
                              dbRs.Open q, dbConn, 2, 2
                              if (myunescape(dbRs("category")) = cat) then
                                    p = p + 1
                                    header = myunescape(dbRs("productheader"))
                                    desc = myunescape(dbRs("productparagraph"))
                                    listing = myunescape(dbRs("productlink"))
                                    listing2 = myunescape(dbRs("productlinkname"))
                                    if (dbRs("producthasalink") = true) then
                                          desc = desc & "<br><span class=""red-bold"">&gt;</span><a href=""" & listing & """ class=""red-bold"">" & listing2 & "</a>"
                                    end if
%>

Here is the new code:

NEW:

<%
            p = 0
            cat = "base"
            displayall = 1
            for each x in Request.Cookies("property")
                  q = "select * from products where product = '" & Request.Cookies("property")(x) & "'"
                              displayall = 0
                              dbRs.Open q, dbConn, 2, 2
                                                            
                              if (myunescape(dbRs("category")) = cat) then
                                    p = p + 1
                                    
                                    header = myunescape(dbRs("productheader"))
                                    desc = myunescape(dbRs("productparagraph"))
                                    listing = myunescape(dbRs("productlink"))
                                    listing2 = myunescape(dbRs("productlinkname"))
                                    if (dbRs("producthasalink") = true) then
                                          desc = desc & "<br><span class=""red-bold"">&gt;</span><a href=""" & listing & """ class=""red-bold"">" & listing2 & "</a>"
                                    end if
%>

I don't quite know 100% what I'm doing but I am learning a ton.  Pretty much the the problem was the Request.Cookies(x)(y) line.  Because of the Google Analytics cookie and the cookie created by the code, I was getting the results of the Google cookie instead of the site's cookie.  Thanks to your code to read the contents of all the cookies related to the site, I noticed the "property" cookie.  So I figured that instead of requesting the entire contents of the cookie, I just needed to specify request.cookie("property")(x) and viola...the site works again.  Like I said, I'm not yet 100% sure what I did but I will dissect this code until I know everything that is going on.  Great way to learn a programming language..  Thank you very much for guiding the way!
You are quite welcome. Glad you got it working!