Passing Data Between Pages

Hi all,

 I have a page which loads data from a database into a table. I would like to take the value of the cell clicked (date) and pass it to another page.

This is what i have so far on the code.

<%  Do Until rsCustomersList.EOF%>
 

<tr>
  <td bgcolor="f7efde" align=center>
    <%= rsCustomersList("FirstName")%>  
    <%= " " %>
    <%= rsCustomersList("LastName") %>
  </td>
  <td bgcolor="f7efde" align=center>
    <%= rsCustomersList("Username")%>  
  </td>

    <td bgcolor="f7efde" align=center>
    <% astring = "<A HREF=bydate.asp?action=SetDate=" & rsCustomersList("Date") & " </A>" %>
    <%= astring %>  
    <%= rsCustomersList("Date")%>  
    </td>

</tr>



<%
rsCustomersList.MoveNext
count = count + 1
Loop

%>

Thanks for any help

Magoo

LVL 1
magoo2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TTomCommented:
I think I see what you are trying to do.  I have no reason to believe it won't work, but you need to close your <a> tag and provide some text for the link.  Perhaps something like:

<% astring = "<A HREF=bydate.asp?action=SetDate=" & rsCustomersList("Date") & ">Click Me</A>" %>

That SHOULD generate something like the following HTML code for each entry:

<a href=bydate.asp?action=SetDate=12-16-99>Click Me</a>

You may run into issues with "s (since there are none) and encoding the date, depending on it's format in the database.

Is this what you are trying to do?

Tom
   

0
mgfranzCommented:
Tom, you are right about the "s, but more with the =Setdate=" synatax.  Try this instead;

<% astring = "<A HREF=bydate.asp?action="SetDate=' & rsCustomersList("Date") & '">Click Me</A>" %>

Mark
0
TTomCommented:
Mark/magoo2:

Actually, I think passing the date format is probably going to be a big old pain, probably something like:

<% astring = "<A HREF=bydate.asp?action="SetDate=' & Server.HTMLEncode(rsCustomersList("Date")) & '">Click Me</A>" %>

(if that's the right syntax)

Tom

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

mgfranzCommented:
The date format is going to wreak havok on the browsers... I know the data will display differently in other countries, but here in the good old US of A, it will appear as 12/17/99  In Perl you can escape the slashes, I don't know if HTMLEncode will pass the date string correctly.  

One way to find out!  :-)
0
mgfranzCommented:
Try this;

<%
SetDate = Server.HTMLEncode(Date())
%>
<A HREF="bydate.asp?action=<%= SetDate %>">Click Me</A>

Mark
0
mgfranzCommented:
As I though the HTMLEncode failed to encode the / properly, so you may want to just delete the / entirely;

<%@ language=VBScript%>

<%
SetDate = Server.HTMLEncode(Date())
SetDate = Replace(SetDate, "/" ,"")
%>
<A HREF="bydate.asp?action=<%= SetDate %>">Click Me</A>
0
clockwatcherCommented:
You want to use URLEncode not HTMLEncode to pass the date.

URLEncode replaces characters that cause problems in URLs (spaces, symbols, etc).

HTMLEncode replaces text with HTML for symbols that give HTML problems (caret signs, apostrophes)

<a href="bydate.asp?action=<%=server.urlencode(date)%>">Click Me</a>

0
TTomCommented:
Good catch, cw.

Tom
0
mgfranzCommented:
The HTMLEncode URLEndode syntax beat me up last week for a good hour... data storage and retrieval... In fact, I ended up using a suggestion by Tom instead;

<%
tText = objRS.Fields("text2")
tText = replace(replace(tText,vbCRLF,"<BR>"),"  ","&nbsp;&nbsp;")
Response.Write tText
%>

( I only needed to catch spaces and <cr>)
0
magoo2Author Commented:
Thanks for all the comments

 The code I pasted earlier doesnt have to stay the way it is (or even close). I just want to pass the value of the date field to the next page the easiest way possible.

It will be using the value of the date field in this SQL query on the next page.

SQLQuery = "SELECT * FROM Customers WHERE Date = #" & setDate & "# ORDER BY LastName"

 Is there a painless way to do that?

Many thanks

Magoo
0
clockwatcherCommented:
<a href="mysearchpage.asp?mydate=<%=server.urlencode("1/1/2000")%>">Look up 1/1/2000</a>


mysearchpage.asp
----------------
sqlquery = "select * from customers where datefield = #" & request.querystring("mydate") & "# order by lastname"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mgfranzCommented:
<a href="mysearchpage.asp?mydate=<%=server.urlencode("Date")%>">Look up <% Date %></a>

' MySearchPage.asp

<%
Dim myDate, Action

myDate = request.querystring("mydate")

sqlquery = "select * from customers where datefield = #" & myDate & "# order by lastname"
 
 
 


0
magoo2Author Commented:
Thank you for the comments. I am accepting clockwatchers comments for the answer (it worked first) , but would like to give you other guys some points for all the info youve given.

One more question...this bit below works great for passing one variable(?) , how would I alter it to pass two variables (Date and Time).

<a href="bydate.asp?mydate=<%=server.urlencode(rsCustomersList("Date"))%>"><%= rsCustomersList("Date")%></a>


Thanks for all the help :)

Magoo
0
mgfranzCommented:
<a href="bydate.asp?mydate=<%=server.urlencode(rsCustomersList("Date"))%>&myTime=<%rsCustomerList(Time")%>"><%= rsCustomersList("Date")%></a>

Mark
0
mgfranzCommented:
I just thought of something... if you are going to do a query on a date field in a dB, what is the search going to find if the look-up string is like this;

myDate = 12%2F17%2F99

How is the dB going to handle the ascii characters on a query?

In other words, the date is going to pass this value to the SQL query as it is, unless you re-process it, or use my suggestion and use Replace()

Mark
0
clockwatcherCommented:
Mark,

Request.Querystring automatically handles the conversion back to normal.  Otherwise, you'd end up with junk when handling your forms on a GET request.

If you actually wanted to use the encoded version of the string, you'd have to use request.servervariables("QUERY_STRING") and parse it yourself.  That's what the request.querystring object does for you.  It parses the querystring into a collection of name/value pairs that are url-DEcoded.
0
mgfranzCommented:
OK... you've lost me.  Obviously this would only work if the query was going to be on 1/1/2000;

<a href="mysearchpage.asp?mydate=<%=server.urlencode("1/1/2000")%>">Look up 1/1/2000</a>

So, we use this instead;

<a href="mysearchpage.asp?mydate=<%=server.urlencode("Date")%>">Look up <% Date %></a>

Whereas when we pass 'mydate' to mysearchpage.asp it is interpreted as either 12%2F17%2F99 or 12/17/99.  Using Request.QueryString() with Get on a form submit would decode the 12%2F17%2F99 string to 12/17/99?

I just don't see where this will work...  If you only want to pass the date as a string var than you could just use this; (without any encoding)

<form method="get">
<A HREF="bydate.asp?action=<%= Date() %>">Click Me</A>
</form>

This works fine in a simple world of browsers because we all know that the / is interpreted fine.

Mark
0
clockwatcherCommented:
Mark,

I think you're completely missing the difference between URLEncode and HTMLEncode.  

An URL is the request.  So '/' isn't fine in an url querystring--- it's a directory separator (e.g., http://www.somewhere.com/directory/a.html?myvar=/what/ever/ is not fine-- some browsers may take it, but some may not).  The reason URLEncode alters the '/' symbol is because that it IS NOT OKAY in an URL.  That's like saying '?' is fine because browsers simply write out a ?.  A '?' is fine in HTML, but it's definitely not fine in an URL.  It demarcates the beginning of the querystring.

That's why there are two functions-- URLEncode and HTMLEncode.  URLEncode makes sure that the URL doesn't contain any characters that may mess with it.  The space is a perfect example of a character that has to be url-encoded.  The following will work fine in Internet Explorer, but won't work in Netscape-- you'll get a malformed URL request.

http://www.somewhere.com/mypage.asp?v1=hello there&v2=whatever

So the safest way to handle a querystring in ALL CASES is to URL encode it.

On the other end, when you retrieve the variables passed within a querystring-- Request.Querystring automatically takes care of unencoding it for you.

Try this simple test-- from your own post above.

bydate.asp
-----------
<html>
<body>
The complete untouched/unparsed querystring was: <%=request.servervariables("QUERY_STRING")%><BR><BR>
But, Request.querystring parses it and gives me this as the action variable: <%=request.querystring("action")%>
</body>
</html>

And call it with the following:

http://www.wherever.com/bydate.asp?action=12%2F17%2F99

The request.querystring will parse the querystring, unencode it and produce 12/17/99.  It's the same thing that happens when you use GET.  The browser's url-encode everything behind the scenes and then pass it to the server.   Try the following:

anothertest.asp
---------------
<html>
<body>
The complete untouched querystring was: <%=request.servervariables("QUERY_STRING")%><BR><BR>
But, Request.querystring parses it and gives me this as the action variable: <%=request.querystring("action")%>
<br><br>
<form method="GET" action="anothertest.asp">
<input name="action" value="12/17/99">
<input type="submit">
</form>
</body>
</html>

Press the submit button, it will GET itself and you'll notice that the browser has url-encoded the 12/17/99 behind the scenes for you-- because the "/" isn't okay in an URL.


----------------------------------------
HTMLEncode is a completely different function and has nothing to do with URLs.  HTMLEncode deals with encoding characters that are special to HTML and may cause the HTML parser to choke.  You're right it wouldn't touch the '/' or the '?', because those don't have any special meaning within HTML.  Its main use is to replace the caret symbols '<' and '>', but it also replaces a few more symbols that might choke the browser.
0
TTomCommented:
cw:

Good explanation.  Thanks!

Tom
0
mgfranzCommented:
Thanks CW, you are a great professor... ;-)  I understand much more clearly now the concepts of URL vs. HTML Encode and it's use with request.querystring().

Thanks,

Mark
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.