Storing Information From URL

B

Bob Barrows [MVP]

Rob said:
Hi,

Can anyone point me in the direction of how to store information
after the ? in the url in form fields.

i.e. http://url/test.asp?User=Rob

in Form Field UserName

Many thanks,

Rob
Here you go:

<%
dim username
username=Request.Querystring("User")

'you could stop here, but it's a good idea to handle any special
'characters that may be contained in the data by using HTMLEncode:

username=Server.HTMLEncode(username)
%>
<html><body><form ... >
<!--Page breaks used for clarity-->
<input name="UserName" type="text" value="
<%=username>
">
</form></body></html>

Bob Barrows
 
R

Rob

Thanks, much appreciated
Bob Barrows said:
Here you go:

<%
dim username
username=Request.Querystring("User")

'you could stop here, but it's a good idea to handle any special
'characters that may be contained in the data by using HTMLEncode:

username=Server.HTMLEncode(username)
%>
<html><body><form ... >
<!--Page breaks used for clarity-->
<input name="UserName" type="text" value="
<%=username>
">
</form></body></html>

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
 
M

McKirahan

Rob said:
Hi,

Can anyone point me in the direction of how to store information after the ?
in the url in form fields.

i.e. http://url/test.asp?User=Rob

in Form Field UserName

Many thanks,

Rob


Store it where? In a database, cookie, session variable?

I'll presume the later in this example.

This creates Session Variables from each "name=value" pair.


<% @Language="VBScript" %>
<% Option Explicit
Dim strRQS
strRQS = Request.QueryString()
'Response.Write("<b>Request.QueryString() :</b> " & strRQS & "<hr>")
Dim arrRQS
arrRQS = Split(strRQS,"&")
Dim arrRQX
Dim intRQS
For intRQS = 0 To UBound(arrRQS)
arrRQX = Split(arrRQS(intRQS),"=")
'Response.Write("Session(" & arrRQX(0) & ") = " & arrRQX(1) & "<br>")
Session(arrRQX(0)) = arrRQX(1)
Next
%>
<html>
<head>
<title>qs_test.asp</title>
</head>
<body>
</body>
</html>


Test it with:

http://localhost/test.asp?A=a&B=b&C=c

Uncomment the "Response.Write" statement to see what happens..
 
B

Bob Barrows [MVP]

McKirahan said:
Store it where? In a database, cookie, session variable?

I think the words "in form fields" provides the answer to this question.

Rob, it's more "appropriate", i.e., less confusing, to use the term
"display" instead of "store" in this situation.

Bob Barrows
 
M

McKirahan

Rob said:
Thanks, much appreciated

"<%=username>" should be "<%=username%>".

Or just:

<input name="UserName" type="text"
value="<%=Server.HTMLEncode(Request.Querystring("User"))%>">


Bob --Thanks for the clarification in the other thread.
 
B

Bob Barrows [MVP]

McKirahan said:
"<%=username>" should be "<%=username%>".
oops


Or just:

<input name="UserName" type="text"
value="<%=Server.HTMLEncode(Request.Querystring("User"))%>">
I tend to avoid "simplifications" such as this. Especially when providing
examples.

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,149
Messages
2,570,841
Members
47,388
Latest member
EarthaGilm

Latest Threads

Top