Request.QueryString help 
Author Message
 Request.QueryString help

Hi,

I'm trying to create html pages based on what is passed or not passed (i.e.
no query string at all) in the query string. I'm using an if -> elseif ->
else statement depending on 3 different factors 1) if the query string
contans "demo" 2)if the query string contains anything at all (i.e. to
access the page you need to use page.asp?someword) and 3)if the query string
contains nothing. My problem is that it only ever recognises if the query
string contains "demo." Everything else is ignored. Here is my code.

IF Request.QueryString("demo") <> " " Then
   SQL_query = "SELECT * FROM table WHERE Abbr ='" &
Request.QueryString("demo") & "' AND demo = 1"
   Set RS = MyConn.Execute(SQL_query)
ElseIf Request.QueryString()  <> " " Then
   SQL_query = "SELECT * FROM table WHERE Abbr ='" & Request.QueryString() &
"'"
   Set RS = MyConn.Execute(SQL_query)
   IF RS("live") <> 1 Then
      iNosite = 1
   End If
Else
<!-- #INCLUDE FILE="nosite.asp" -->
End If

I've tried debugging by outputting the SQL_query and the only time the sql
query ever shows up is in the first if. To qualify this post, I'm really new
to VBScript but I have a background in PHP and Perl and in those languages I
would only have to say if ($whatever) to see if a variable was
populated/existed. So I don't know how to check for the existence of a
variable in VBScript.

Thanks in advance,
Stephanie



Wed, 08 Sep 2004 15:28:03 GMT  
 Request.QueryString help
Add    Response.Write Request.QueryString to see
what exactly is being 'passed' then you can check
to see if your If/Then/Else tests are behaving the way
they should be as written.

The queryString might actually be in the address bar
if you didn't use a Form with METHOD=POST, everything
after the '?' .

MSDN Request.QueryString:
http://msdn.microsoft.com/library/en-us/iisref/html/psdk/asp/vbob53hj...

Bill Wallace


Quote:
> Hi,

> I'm trying to create html pages based on what is passed or not passed (i.e.
> no query string at all) in the query string. I'm using an if -> elseif ->
> else statement depending on 3 different factors 1) if the query string
> contans "demo" 2)if the query string contains anything at all (i.e. to
> access the page you need to use page.asp?someword) and 3)if the query string
> contains nothing. My problem is that it only ever recognises if the query
> string contains "demo." Everything else is ignored. Here is my code.

> IF Request.QueryString("demo") <> " " Then
>    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> Request.QueryString("demo") & "' AND demo = 1"
>    Set RS = MyConn.Execute(SQL_query)
> ElseIf Request.QueryString()  <> " " Then
>    SQL_query = "SELECT * FROM table WHERE Abbr ='" & Request.QueryString() &
> "'"
>    Set RS = MyConn.Execute(SQL_query)
>    IF RS("live") <> 1 Then
>       iNosite = 1
>    End If
> Else
> <!-- #INCLUDE FILE="nosite.asp" -->
> End If

> I've tried debugging by outputting the SQL_query and the only time the sql
> query ever shows up is in the first if. To qualify this post, I'm really new
> to VBScript but I have a background in PHP and Perl and in those languages I
> would only have to say if ($whatever) to see if a variable was
> populated/existed. So I don't know how to check for the existence of a
> variable in VBScript.

> Thanks in advance,
> Stephanie




Wed, 08 Sep 2004 17:17:50 GMT  
 Request.QueryString help
I'd break this a part a little and perhaps change your logic:

Private strDemo
strDemo = Request.QueryString("demo")

Private strQS
strQS = Request.QueryString

Private SQL_query
SQL_query = ""

If Len(strDemo) Then
     SQL_query = "SELECT * FROM table WHERE Abbr ='" & strDemo & "' AND demo
= 1"
ElseIf Len(strQS) Then
      SQL_query = "SELECT * FROM table WHERE Abbr ='" & strQS & "'"
Else
    '-- Thers is no DEMO and no QueryString ...
End If

Obviously you'll have to shape this for your needs, but I would say that it
pretty much gets there ...


Quote:
> Hi,

> I'm trying to create html pages based on what is passed or not passed
(i.e.
> no query string at all) in the query string. I'm using an if -> elseif ->
> else statement depending on 3 different factors 1) if the query string
> contans "demo" 2)if the query string contains anything at all (i.e. to
> access the page you need to use page.asp?someword) and 3)if the query
string
> contains nothing. My problem is that it only ever recognises if the query
> string contains "demo." Everything else is ignored. Here is my code.

> IF Request.QueryString("demo") <> " " Then
>    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> Request.QueryString("demo") & "' AND demo = 1"
>    Set RS = MyConn.Execute(SQL_query)
> ElseIf Request.QueryString()  <> " " Then
>    SQL_query = "SELECT * FROM table WHERE Abbr ='" & Request.QueryString()
&
> "'"
>    Set RS = MyConn.Execute(SQL_query)
>    IF RS("live") <> 1 Then
>       iNosite = 1
>    End If
> Else
> <!-- #INCLUDE FILE="nosite.asp" -->
> End If

> I've tried debugging by outputting the SQL_query and the only time the sql
> query ever shows up is in the first if. To qualify this post, I'm really
new
> to VBScript but I have a background in PHP and Perl and in those languages
I
> would only have to say if ($whatever) to see if a variable was
> populated/existed. So I don't know how to check for the existence of a
> variable in VBScript.

> Thanks in advance,
> Stephanie




Wed, 08 Sep 2004 21:43:33 GMT  
 Request.QueryString help
Jennifer,

Thanks, that's exactly what I needed and it works like a charm! So, just so
that I understand this, you have to reassign the Request.QueryString to a
variable and then test for the variable's length to see if it exists meaning
that there isn't a function in VBScript to check for existance? I ask
because in other languages there are functions like isset() or exists() and
ways to tell if something is a string or array, etc. like is_array().

Thanks again for all your help!

Stephanie


Quote:
> I'd break this a part a little and perhaps change your logic:

> Private strDemo
> strDemo = Request.QueryString("demo")

> Private strQS
> strQS = Request.QueryString

> Private SQL_query
> SQL_query = ""

> If Len(strDemo) Then
>      SQL_query = "SELECT * FROM table WHERE Abbr ='" & strDemo & "' AND
demo
> = 1"
> ElseIf Len(strQS) Then
>       SQL_query = "SELECT * FROM table WHERE Abbr ='" & strQS & "'"
> Else
>     '-- Thers is no DEMO and no QueryString ...
> End If

> Obviously you'll have to shape this for your needs, but I would say that
it
> pretty much gets there ...



> > Hi,

> > I'm trying to create html pages based on what is passed or not passed
> (i.e.
> > no query string at all) in the query string. I'm using an if ->
elseif ->
> > else statement depending on 3 different factors 1) if the query string
> > contans "demo" 2)if the query string contains anything at all (i.e. to
> > access the page you need to use page.asp?someword) and 3)if the query
> string
> > contains nothing. My problem is that it only ever recognises if the
query
> > string contains "demo." Everything else is ignored. Here is my code.

> > IF Request.QueryString("demo") <> " " Then
> >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> > Request.QueryString("demo") & "' AND demo = 1"
> >    Set RS = MyConn.Execute(SQL_query)
> > ElseIf Request.QueryString()  <> " " Then
> >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &

Request.QueryString()

- Show quoted text -

Quote:
> &
> > "'"
> >    Set RS = MyConn.Execute(SQL_query)
> >    IF RS("live") <> 1 Then
> >       iNosite = 1
> >    End If
> > Else
> > <!-- #INCLUDE FILE="nosite.asp" -->
> > End If

> > I've tried debugging by outputting the SQL_query and the only time the
sql
> > query ever shows up is in the first if. To qualify this post, I'm really
> new
> > to VBScript but I have a background in PHP and Perl and in those
languages
> I
> > would only have to say if ($whatever) to see if a variable was
> > populated/existed. So I don't know how to check for the existence of a
> > variable in VBScript.

> > Thanks in advance,
> > Stephanie




Thu, 09 Sep 2004 08:02:12 GMT  
 Request.QueryString help

Quote:

> Jennifer,

> Thanks, that's exactly what I needed and it works like a charm! So, just so
> that I understand this, you have to reassign the Request.QueryString to a
> variable and then test for the variable's length to see if it exists meaning
> that there isn't a function in VBScript to check for existance? I ask
> because in other languages there are functions like isset() or exists() and
> ways to tell if something is a string or array, etc. like is_array().

VBScript has the followinf Is-functions:

IsArray
IsDate
IsEmpty
IsNull
IsNumeric
IsObject

The VarType function is also pretty flexible, it returns a value indicating the
subtype of a variable.

The VarType function returns the following values:

Constant | Value | Description
-----------------------------------------------------------
vbEmpty 0 Empty (uninitialized)
vbNull 1 Null (no valid data)
vbInteger 2 Integer
vbLong 3 Long integer
vbSingle 4 Single-precision floating-point number
vbDouble 5 Double-precision floating-point number
vbCurrency 6 Currency
vbDate 7 Date
vbString 8 String
vbObject 9 Automation object
vbError 10 Error
vbBoolean 11 Boolean
vbVariant 12 Variant (used only with arrays of Variants)
vbDataObject 13 A data-access object
vbByte 17 Byte
vbArray 8192 Array

--
torgeir



Thu, 09 Sep 2004 08:16:12 GMT  
 Request.QueryString help
You can test for the presence of a querystring with:

if request.querystring.count = 0 then
    'no name=value pairs
else
    '1 or more name=value pairs
end if

If no querystring is present, count will be 0 otherwise it will be the number of name=value pairs...

Note: odd urls like the 2 below are valid even if they may not make much sense ;-)

    blah.asp?foo            count = 1 (a name only)
    blah.asp?foo=a&bar      count = 2 (a name/value pair plus a name only)

A form submission via the GET method won't create these but they can be created manually (by typing directly in the address bar) or via script generated urls...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> Jennifer,

> Thanks, that's exactly what I needed and it works like a charm! So, just so
> that I understand this, you have to reassign the Request.QueryString to a
> variable and then test for the variable's length to see if it exists meaning
> that there isn't a function in VBScript to check for existance? I ask
> because in other languages there are functions like isset() or exists() and
> ways to tell if something is a string or array, etc. like is_array().

> Thanks again for all your help!

> Stephanie



> > I'd break this a part a little and perhaps change your logic:

> > Private strDemo
> > strDemo = Request.QueryString("demo")

> > Private strQS
> > strQS = Request.QueryString

> > Private SQL_query
> > SQL_query = ""

> > If Len(strDemo) Then
> >      SQL_query = "SELECT * FROM table WHERE Abbr ='" & strDemo & "' AND
> demo
> > = 1"
> > ElseIf Len(strQS) Then
> >       SQL_query = "SELECT * FROM table WHERE Abbr ='" & strQS & "'"
> > Else
> >     '-- Thers is no DEMO and no QueryString ...
> > End If

> > Obviously you'll have to shape this for your needs, but I would say that
> it
> > pretty much gets there ...



> > > Hi,

> > > I'm trying to create html pages based on what is passed or not passed
> > (i.e.
> > > no query string at all) in the query string. I'm using an if ->
> elseif ->
> > > else statement depending on 3 different factors 1) if the query string
> > > contans "demo" 2)if the query string contains anything at all (i.e. to
> > > access the page you need to use page.asp?someword) and 3)if the query
> > string
> > > contains nothing. My problem is that it only ever recognises if the
> query
> > > string contains "demo." Everything else is ignored. Here is my code.

> > > IF Request.QueryString("demo") <> " " Then
> > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> > > Request.QueryString("demo") & "' AND demo = 1"
> > >    Set RS = MyConn.Execute(SQL_query)
> > > ElseIf Request.QueryString()  <> " " Then
> > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> Request.QueryString()
> > &
> > > "'"
> > >    Set RS = MyConn.Execute(SQL_query)
> > >    IF RS("live") <> 1 Then
> > >       iNosite = 1
> > >    End If
> > > Else
> > > <!-- #INCLUDE FILE="nosite.asp" -->
> > > End If

> > > I've tried debugging by outputting the SQL_query and the only time the
> sql
> > > query ever shows up is in the first if. To qualify this post, I'm really
> > new
> > > to VBScript but I have a background in PHP and Perl and in those
> languages
> > I
> > > would only have to say if ($whatever) to see if a variable was
> > > populated/existed. So I don't know how to check for the existence of a
> > > variable in VBScript.

> > > Thanks in advance,
> > > Stephanie




Thu, 09 Sep 2004 08:54:59 GMT  
 Request.QueryString help
Dear Stephanie,

You can check for an empty string "" (there are no spaces in there) and it
will work for a check against the querystring.

I tend to populate variables before hand, because if you do something like
this:

If Request.QueryString("name") <> "" Then
    Response.Write Request.QueryString("name")
End If

This does two requests to the querystring, and that's a performance hit and
poor coding (or, weak coding). Hit the QS and then use your variables from
then on.

Additionally, I tend to use this function alot:
Function nZ(passed, ifNull)
 If isNull(Passed) Or passed="" Then
  nZ = ifNull
 Else
  nZ = passed
 End If
End Function

Now you can do something like:
strName = nZ(Request.QueryString("name"), "noname")

In other words, it's a great way to substitute a value if nothing was
supplied, which is awesome for validationand instances such as:

If Request.QueryString("name") = "" Then strName = "noname" End If

You may want to check out isEmpty, isNull ... and even consider a function
such as this:

Function isBlank(passed)
 Passed = Trim(Passed)
 If isNull(passed) Or isEmpty(passed) Or Passed="" Then
  isBlank = true
 Else
  isBlank = false
 End If
End Function

Now you could say: If isBlank(Request.QueryString) Then ...


Quote:
> Jennifer,

> Thanks, that's exactly what I needed and it works like a charm! So, just
so
> that I understand this, you have to reassign the Request.QueryString to a
> variable and then test for the variable's length to see if it exists
meaning
> that there isn't a function in VBScript to check for existance? I ask
> because in other languages there are functions like isset() or exists()
and
> ways to tell if something is a string or array, etc. like is_array().

> Thanks again for all your help!

> Stephanie



> > I'd break this a part a little and perhaps change your logic:

> > Private strDemo
> > strDemo = Request.QueryString("demo")

> > Private strQS
> > strQS = Request.QueryString

> > Private SQL_query
> > SQL_query = ""

> > If Len(strDemo) Then
> >      SQL_query = "SELECT * FROM table WHERE Abbr ='" & strDemo & "' AND
> demo
> > = 1"
> > ElseIf Len(strQS) Then
> >       SQL_query = "SELECT * FROM table WHERE Abbr ='" & strQS & "'"
> > Else
> >     '-- Thers is no DEMO and no QueryString ...
> > End If

> > Obviously you'll have to shape this for your needs, but I would say that
> it
> > pretty much gets there ...



> > > Hi,

> > > I'm trying to create html pages based on what is passed or not passed
> > (i.e.
> > > no query string at all) in the query string. I'm using an if ->
> elseif ->
> > > else statement depending on 3 different factors 1) if the query string
> > > contans "demo" 2)if the query string contains anything at all (i.e. to
> > > access the page you need to use page.asp?someword) and 3)if the query
> > string
> > > contains nothing. My problem is that it only ever recognises if the
> query
> > > string contains "demo." Everything else is ignored. Here is my code.

> > > IF Request.QueryString("demo") <> " " Then
> > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> > > Request.QueryString("demo") & "' AND demo = 1"
> > >    Set RS = MyConn.Execute(SQL_query)
> > > ElseIf Request.QueryString()  <> " " Then
> > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> Request.QueryString()
> > &
> > > "'"
> > >    Set RS = MyConn.Execute(SQL_query)
> > >    IF RS("live") <> 1 Then
> > >       iNosite = 1
> > >    End If
> > > Else
> > > <!-- #INCLUDE FILE="nosite.asp" -->
> > > End If

> > > I've tried debugging by outputting the SQL_query and the only time the
> sql
> > > query ever shows up is in the first if. To qualify this post, I'm
really
> > new
> > > to VBScript but I have a background in PHP and Perl and in those
> languages
> > I
> > > would only have to say if ($whatever) to see if a variable was
> > > populated/existed. So I don't know how to check for the existence of a
> > > variable in VBScript.

> > > Thanks in advance,
> > > Stephanie




Thu, 09 Sep 2004 08:57:32 GMT  
 Request.QueryString help
Michael,

Can you also reference the querystring object ordinally (sp?) .. in other
words, by index rather than name value?



You can test for the presence of a querystring with:

if request.querystring.count = 0 then
    'no name=value pairs
else
    '1 or more name=value pairs
end if

If no querystring is present, count will be 0 otherwise it will be the
number of name=value pairs...

Note: odd urls like the 2 below are valid even if they may not make much
sense ;-)

    blah.asp?foo            count = 1 (a name only)
    blah.asp?foo=a&bar      count = 2 (a name/value pair plus a name only)

A form submission via the GET method won't create these but they can be
created manually (by typing directly in the address bar) or via script
generated urls...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:
> Jennifer,

> Thanks, that's exactly what I needed and it works like a charm! So, just
so
> that I understand this, you have to reassign the Request.QueryString to a
> variable and then test for the variable's length to see if it exists
meaning
> that there isn't a function in VBScript to check for existance? I ask
> because in other languages there are functions like isset() or exists()
and
> ways to tell if something is a string or array, etc. like is_array().

> Thanks again for all your help!

> Stephanie



> > I'd break this a part a little and perhaps change your logic:

> > Private strDemo
> > strDemo = Request.QueryString("demo")

> > Private strQS
> > strQS = Request.QueryString

> > Private SQL_query
> > SQL_query = ""

> > If Len(strDemo) Then
> >      SQL_query = "SELECT * FROM table WHERE Abbr ='" & strDemo & "' AND
> demo
> > = 1"
> > ElseIf Len(strQS) Then
> >       SQL_query = "SELECT * FROM table WHERE Abbr ='" & strQS & "'"
> > Else
> >     '-- Thers is no DEMO and no QueryString ...
> > End If

> > Obviously you'll have to shape this for your needs, but I would say that
> it
> > pretty much gets there ...



> > > Hi,

> > > I'm trying to create html pages based on what is passed or not passed
> > (i.e.
> > > no query string at all) in the query string. I'm using an if ->
> elseif ->
> > > else statement depending on 3 different factors 1) if the query string
> > > contans "demo" 2)if the query string contains anything at all (i.e. to
> > > access the page you need to use page.asp?someword) and 3)if the query
> > string
> > > contains nothing. My problem is that it only ever recognises if the
> query
> > > string contains "demo." Everything else is ignored. Here is my code.

> > > IF Request.QueryString("demo") <> " " Then
> > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> > > Request.QueryString("demo") & "' AND demo = 1"
> > >    Set RS = MyConn.Execute(SQL_query)
> > > ElseIf Request.QueryString()  <> " " Then
> > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> Request.QueryString()
> > &
> > > "'"
> > >    Set RS = MyConn.Execute(SQL_query)
> > >    IF RS("live") <> 1 Then
> > >       iNosite = 1
> > >    End If
> > > Else
> > > <!-- #INCLUDE FILE="nosite.asp" -->
> > > End If

> > > I've tried debugging by outputting the SQL_query and the only time the
> sql
> > > query ever shows up is in the first if. To qualify this post, I'm
really
> > new
> > > to VBScript but I have a background in PHP and Perl and in those
> languages
> > I
> > > would only have to say if ($whatever) to see if a variable was
> > > populated/existed. So I don't know how to check for the existence of a
> > > variable in VBScript.

> > > Thanks in advance,
> > > Stephanie




Thu, 09 Sep 2004 08:59:36 GMT  
 Request.QueryString help
Save this as test.asp and try it from the browser address bar with various query strings to get a feel for how a query string gets parsed into name/value pairs...

<%
response.write "count=" & request.querystring.count
response.write "<br>"
if request.querystring.count > 0 then
  for n = 1 to request.querystring.count
    response.write _
      request.querystring.key(n) & "=" & _
      request.querystring.item(n)
    response.write "<br>"
  next
end if
%>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> Michael,

> Can you also reference the querystring object ordinally (sp?) .. in other
> words, by index rather than name value?



> You can test for the presence of a querystring with:

> if request.querystring.count = 0 then
>     'no name=value pairs
> else
>     '1 or more name=value pairs
> end if

> If no querystring is present, count will be 0 otherwise it will be the
> number of name=value pairs...

> Note: odd urls like the 2 below are valid even if they may not make much
> sense ;-)

>     blah.asp?foo            count = 1 (a name only)
>     blah.asp?foo=a&bar      count = 2 (a name/value pair plus a name only)

> A form submission via the GET method won't create these but they can be
> created manually (by typing directly in the address bar) or via script
> generated urls...

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US
> --


> > Jennifer,

> > Thanks, that's exactly what I needed and it works like a charm! So, just
> so
> > that I understand this, you have to reassign the Request.QueryString to a
> > variable and then test for the variable's length to see if it exists
> meaning
> > that there isn't a function in VBScript to check for existance? I ask
> > because in other languages there are functions like isset() or exists()
> and
> > ways to tell if something is a string or array, etc. like is_array().

> > Thanks again for all your help!

> > Stephanie



> > > I'd break this a part a little and perhaps change your logic:

> > > Private strDemo
> > > strDemo = Request.QueryString("demo")

> > > Private strQS
> > > strQS = Request.QueryString

> > > Private SQL_query
> > > SQL_query = ""

> > > If Len(strDemo) Then
> > >      SQL_query = "SELECT * FROM table WHERE Abbr ='" & strDemo & "' AND
> > demo
> > > = 1"
> > > ElseIf Len(strQS) Then
> > >       SQL_query = "SELECT * FROM table WHERE Abbr ='" & strQS & "'"
> > > Else
> > >     '-- Thers is no DEMO and no QueryString ...
> > > End If

> > > Obviously you'll have to shape this for your needs, but I would say that
> > it
> > > pretty much gets there ...



> > > > Hi,

> > > > I'm trying to create html pages based on what is passed or not passed
> > > (i.e.
> > > > no query string at all) in the query string. I'm using an if ->
> > elseif ->
> > > > else statement depending on 3 different factors 1) if the query string
> > > > contans "demo" 2)if the query string contains anything at all (i.e. to
> > > > access the page you need to use page.asp?someword) and 3)if the query
> > > string
> > > > contains nothing. My problem is that it only ever recognises if the
> > query
> > > > string contains "demo." Everything else is ignored. Here is my code.

> > > > IF Request.QueryString("demo") <> " " Then
> > > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> > > > Request.QueryString("demo") & "' AND demo = 1"
> > > >    Set RS = MyConn.Execute(SQL_query)
> > > > ElseIf Request.QueryString()  <> " " Then
> > > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> > Request.QueryString()
> > > &
> > > > "'"
> > > >    Set RS = MyConn.Execute(SQL_query)
> > > >    IF RS("live") <> 1 Then
> > > >       iNosite = 1
> > > >    End If
> > > > Else
> > > > <!-- #INCLUDE FILE="nosite.asp" -->
> > > > End If

> > > > I've tried debugging by outputting the SQL_query and the only time the
> > sql
> > > > query ever shows up is in the first if. To qualify this post, I'm
> really
> > > new
> > > > to VBScript but I have a background in PHP and Perl and in those
> > languages
> > > I
> > > > would only have to say if ($whatever) to see if a variable was
> > > > populated/existed. So I don't know how to check for the existence of a
> > > > variable in VBScript.

> > > > Thanks in advance,
> > > > Stephanie




Thu, 09 Sep 2004 10:24:35 GMT  
 Request.QueryString help
"key" and "item" .. those are the keywords here. I've not seen these used
before, could be useful. Thanks :)



Save this as test.asp and try it from the browser address bar with various
query strings to get a feel for how a query string gets parsed into
name/value pairs...

<%
response.write "count=" & request.querystring.count
response.write "<br>"
if request.querystring.count > 0 then
  for n = 1 to request.querystring.count
    response.write _
      request.querystring.key(n) & "=" & _
      request.querystring.item(n)
    response.write "<br>"
  next
end if
%>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:
> Michael,

> Can you also reference the querystring object ordinally (sp?) .. in other
> words, by index rather than name value?



> You can test for the presence of a querystring with:

> if request.querystring.count = 0 then
>     'no name=value pairs
> else
>     '1 or more name=value pairs
> end if

> If no querystring is present, count will be 0 otherwise it will be the
> number of name=value pairs...

> Note: odd urls like the 2 below are valid even if they may not make much
> sense ;-)

>     blah.asp?foo            count = 1 (a name only)
>     blah.asp?foo=a&bar      count = 2 (a name/value pair plus a name only)

> A form submission via the GET method won't create these but they can be
> created manually (by typing directly in the address bar) or via script
> generated urls...

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US
> --


> > Jennifer,

> > Thanks, that's exactly what I needed and it works like a charm! So, just
> so
> > that I understand this, you have to reassign the Request.QueryString to
a
> > variable and then test for the variable's length to see if it exists
> meaning
> > that there isn't a function in VBScript to check for existance? I ask
> > because in other languages there are functions like isset() or exists()
> and
> > ways to tell if something is a string or array, etc. like is_array().

> > Thanks again for all your help!

> > Stephanie



> > > I'd break this a part a little and perhaps change your logic:

> > > Private strDemo
> > > strDemo = Request.QueryString("demo")

> > > Private strQS
> > > strQS = Request.QueryString

> > > Private SQL_query
> > > SQL_query = ""

> > > If Len(strDemo) Then
> > >      SQL_query = "SELECT * FROM table WHERE Abbr ='" & strDemo & "'
AND
> > demo
> > > = 1"
> > > ElseIf Len(strQS) Then
> > >       SQL_query = "SELECT * FROM table WHERE Abbr ='" & strQS & "'"
> > > Else
> > >     '-- Thers is no DEMO and no QueryString ...
> > > End If

> > > Obviously you'll have to shape this for your needs, but I would say
that
> > it
> > > pretty much gets there ...



> > > > Hi,

> > > > I'm trying to create html pages based on what is passed or not
passed
> > > (i.e.
> > > > no query string at all) in the query string. I'm using an if ->
> > elseif ->
> > > > else statement depending on 3 different factors 1) if the query
string
> > > > contans "demo" 2)if the query string contains anything at all (i.e.
to
> > > > access the page you need to use page.asp?someword) and 3)if the
query
> > > string
> > > > contains nothing. My problem is that it only ever recognises if the
> > query
> > > > string contains "demo." Everything else is ignored. Here is my code.

> > > > IF Request.QueryString("demo") <> " " Then
> > > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> > > > Request.QueryString("demo") & "' AND demo = 1"
> > > >    Set RS = MyConn.Execute(SQL_query)
> > > > ElseIf Request.QueryString()  <> " " Then
> > > >    SQL_query = "SELECT * FROM table WHERE Abbr ='" &
> > Request.QueryString()
> > > &
> > > > "'"
> > > >    Set RS = MyConn.Execute(SQL_query)
> > > >    IF RS("live") <> 1 Then
> > > >       iNosite = 1
> > > >    End If
> > > > Else
> > > > <!-- #INCLUDE FILE="nosite.asp" -->
> > > > End If

> > > > I've tried debugging by outputting the SQL_query and the only time
the
> > sql
> > > > query ever shows up is in the first if. To qualify this post, I'm
> really
> > > new
> > > > to VBScript but I have a background in PHP and Perl and in those
> > languages
> > > I
> > > > would only have to say if ($whatever) to see if a variable was
> > > > populated/existed. So I don't know how to check for the existence of
a
> > > > variable in VBScript.

> > > > Thanks in advance,
> > > > Stephanie

me)



Thu, 09 Sep 2004 11:15:01 GMT  
 Request.QueryString help

Quote:

> "key" and "item" .. those are the keywords here. I've not seen these used
> before, could be useful. Thanks :)

IVariantDictionary and IStringList are the interfaces behind most (if not all) of the ASP collection objects including Request.Form and Request.QueryString.

http://www.google.com/search?as_q=ivariantdictionary
http://www.google.com/search?as_q=istringlist

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Thu, 09 Sep 2004 11:56:25 GMT  
 Request.QueryString help
::groan::

Yet something else to research, lol. I'm a glutton for punishment.

Thanks for the links :)




Quote:
> "key" and "item" .. those are the keywords here. I've not seen these used
> before, could be useful. Thanks :)

IVariantDictionary and IStringList are the interfaces behind most (if not
all) of the ASP collection objects including Request.Form and
Request.QueryString.

http://www.google.com/search?as_q=ivariantdictionary
http://www.google.com/search?as_q=istringlist

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Thu, 09 Sep 2004 12:00:12 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Need more Request.QueryString and Request.Form help

2. Can I Request.form and Request.querystring?

3. How to use VBA to send Request QueryString to an ASP page

4. Serializing Request.Querystring

5. NameValueCollection, Request.QueryString, WebForm usage

6. For each sKey in Request.QueryString returns Error 451

7. Request.Querystring

8. Problems with listbox and asp and request.querystring.

9. Request.QueryString

10. request.querystring in JavaScript?

11. Request.QueryString

12. VBScript Equivalent to Request.Querystring

 

 
Powered by phpBB® Forum Software