Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does anyone know how i can create parameters in my ASP?

Status
Not open for further replies.

ruthcali

Programmer
Apr 27, 2000
470
US
i am using Windows NT 4.0 with Option Pack 4.0 and Access 97.

I have an Access97 database that i want users to be able to query from a webpage.

Does anyone know how i can create parameters in my ASP? So on the webpage, have a drop down box where the user can choose what record he wants to see info for.

thanks,
ruth ruth.jonkman@wcom.com
 
Hello,

Yes you can, for example

you have a combo box for this for name,
and the options are 1,2,3,4,5
and when the person submit the form it goes into another form which process the sql accordingly.

Thanks,
Hui Emagine Solutions, Inc.
 
Hi Hui,

but how do i do that? :)
ruth.jonkman@wcom.com
 
Here is some code maybe you can understand

You have a database with 5 tables:
1. Car
2. Boat
3. Star
4. House
5. Computer

This is inside a html in form, the form must have a action that submits to a asp form named (whatever).asp

<SELECT name=&quot;type&quot; class='box1'>
<OPTION value='1'>Car</OPTION>
<OPTION value='2'>Boat</OPTION>
<OPTION value='3'>Star</OPTION>
<OPTION value='4'>House</OPTION>
<OPTION value='5'>Computer</OPTION>
</SELECT>

This is inside the whatever.asp page

type =Request.Form(&quot;type&quot;)

if (type = 1) then
sqltext = &quot;SELECT * FROM Car&quot;
elseif (type = 2) then
sqltext = &quot;SELECT * FROM Boat&quot;
elseif (type = 3) then
sqltext = &quot;SELECT * FROM Star&quot;
elseif (type = 4) then
sqltext = &quot;SELECT * FROM House&quot;
elseif (type = 5) then
sqltext = &quot;SELECT * FROM Computer&quot;
end if

set cnn = Server.CreateObject(&quot;ADODB.Connection&quot;)
cnn.Open &quot;driver={Microsoft Access Driver (*.mdb)};;DBQ=(physical path of your database);&quot;
set Result = cnn.Execute(sqltext)

do until Results.eof
Response.Write(Results(&quot;whatever is in your database&quot;)))
Results.movenext
loop Emagine Solutions, Inc.
 
For Example all the tables have a field call Cost

SO you would do a do until Results.eof
Response.Write(Results(&quot;Cost&quot;))
Results.movenext
loop

-> set Result = cnn.Execute(sqltext)
is suppose to be set Results <- with a s

hope that helps.
hui Emagine Solutions, Inc.
 
Hi Hui,

First, i created a html page called test.html.

<HTML>
<HEAD>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html;charset=windows-1252&quot;>
<TITLE>Query1</TITLE>
<BODY>

<SELECT name=&quot;type&quot; class='box1'>
<OPTION value='1'>Car</OPTION>
<OPTION value='2'>Boat</OPTION>
<OPTION value='3'>Star</OPTION>
<OPTION value='4'>House</OPTION>
<OPTION value='5'>Computer</OPTION>
</SELECT>

<FORM METHOD=&quot;GET&quot; ACTION=&quot;Test.ASP&quot;>

</FORM>
</BODY>
</HTML>


Then i created an ASP page called Test.asp:

<% @Language=VBScript %>
<html dir=&quot;ltr&quot;>

<head>
<title>test</title>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
type =Request.Form(&quot;type&quot;)

if (type = 1) then
sqltext = &quot;SELECT * FROM Car&quot;
elseif (type = 2) then
sqltext = &quot;SELECT * FROM Boat&quot;
elseif (type = 3) then
sqltext = &quot;SELECT * FROM Star&quot;
elseif (type = 4) then
sqltext = &quot;SELECT * FROM House&quot;
elseif (type = 5) then
sqltext = &quot;SELECT * FROM Computer&quot;
end if

set cnn = Server.CreateObject(&quot;ADODB.Connection&quot;)
cnn.Open &quot;driver={Microsoft Access Driver (*.mdb)};;DBQ=E:\Inetpub\set Result = cnn.Execute(sqltext)

do until Results.eof
Response.Write(Results(&quot;whatever is in your database&quot;)))
Results.movenext
loop

</body>
</html>


Then i made a database with tables called Car, Boat, Star, House, Computers.

then i went to my browser and typed:
Am i missing something because it's not working.

thanks,
ruth ruth.jonkman@wcom.com
 
Asp code u need a <% and ends with %>

the combo box should be inside the form

move all the select statements into the <from>

and put <% before type = Request.Form and put %> after loop.

Also you will need IIS4.0 or IIS5.0 what os are you using?

the tables for those made a field name Cost
and put dummie variables in it..
Results(&quot;whatever &quot;) is suppose to be Results(&quot;Cost&quot;) Emagine Solutions, Inc.
 
Hi hui,

this is my test.html:
<HTML>
<HEAD>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html;charset=windows-1252&quot;>
<TITLE>Query1</TITLE>
<BODY>

<form>
<SELECT name=&quot;type&quot; class='box1'>
<OPTION value='1'>Car</OPTION>
<OPTION value='2'>Boat</OPTION>
<OPTION value='3'>Star</OPTION>
<OPTION value='4'>House</OPTION>
<OPTION value='5'>Computer</OPTION>
</SELECT>

<FORM METHOD=&quot;GET&quot; ACTION=&quot;Test.ASP&quot;>

<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Run Query&quot;>

</FORM>
</BODY>
</HTML>


and this is my test.asp:
<% @Language=VBScript %>
<html>

<head>
<title>test</title>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

<% type=Request.Form(&quot;type&quot;) %>



'Connects to the Access driver and Access database in the Inetpub directory where the database is saved
strProvider = &quot;Driver={Microsoft Access Driver (*.mdb)}; DBQ=E:\Inetpub\'Creates an instance of an Active Server component
set objConn = server.createobject(&quot;ADODB.Connection&quot;)
'Opens the connection to the data store
objConn.Open strProvider
'Instantiate Command object and use ActiveConnection property to
'attach connection to Command object
set cm = Server.CreateObject(&quot;ADODB.Command&quot;)
cm.ActiveConnection = objConn

<form>

if (type = 1) then
sqltext = &quot;SELECT * FROM Car&quot;
elseif (type = 2) then
sqltext = &quot;SELECT * FROM Boat&quot;
elseif (type = 3) then
sqltext = &quot;SELECT * FROM Star&quot;
elseif (type = 4) then
sqltext = &quot;SELECT * FROM House&quot;
elseif (type = 5) then
sqltext = &quot;SELECT * FROM Computer&quot;
end if

'set cnn = Server.CreateObject(&quot;ADODB.Connection&quot;)
'cnn.Open &quot;driver={Microsoft Access Driver (*.mdb)};;DBQ=E:\Inetpub\
set Result = cnn.Execute(sqltext)

do until Results.eof
Response.Write(Results(&quot;Cost&quot;)))
Results.movenext
<% loop %>

</form>
</body>
</html>

I put <form> before the combo box in the test.html and before the select statements in the test.asp.
i put <%type=request.form%> and <%loop%>
i went to my database and made a field called 'Cost'.
i am using Windows NT 4.0 and IIS 5.0.

it's still not working though.
ruth
ruth.jonkman@wcom.com
 
Umm, you did it wrong.

HTML>
<HEAD>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html;charset=windows-1252&quot;>
<TITLE>Query1</TITLE>
<BODY>




<FORM METHOD=&quot;Post&quot; ACTION=&quot;Test.ASP&quot;>
<SELECT name=&quot;type&quot; class='box1'>
<OPTION value='1'>Car</OPTION>
<OPTION value='2'>Boat</OPTION>
<OPTION value='3'>Star</OPTION>
<OPTION value='4'>House</OPTION>
<OPTION value='5'>Computer</OPTION>
</SELECT>
<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Run Query&quot;>

</FORM>
</BODY>
</HTML>


and this is my test.asp:
<% @Language=VBScript %>
<html>

<head>
<title>test</title>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

<% type=Request.Form(&quot;type&quot;)

'Connects to the Access driver and Access database in the Inetpub directory where the database is saved
strProvider = &quot;Driver={Microsoft Access Driver (*.mdb)}; DBQ=E:\Inetpub\'Creates an instance of an Active Server component
set objConn = server.createobject(&quot;ADODB.Connection&quot;)
'Opens the connection to the data store
objConn.Open strProvider
'Instantiate Command object and use ActiveConnection property to
'attach connection to Command object
set cm = Server.CreateObject(&quot;ADODB.Command&quot;)
cm.ActiveConnection = objConn

if (type = 1) then
sqltext = &quot;SELECT * FROM Car&quot;
elseif (type = 2) then
sqltext = &quot;SELECT * FROM Boat&quot;
elseif (type = 3) then
sqltext = &quot;SELECT * FROM Star&quot;
elseif (type = 4) then
sqltext = &quot;SELECT * FROM House&quot;
elseif (type = 5) then
sqltext = &quot;SELECT * FROM Computer&quot;
end if

'set cnn = Server.CreateObject(&quot;ADODB.Connection&quot;)
'cnn.Open &quot;driver={Microsoft Access Driver (*.mdb)};;DBQ=E:\Inetpub\
set Result = cnn.Execute(sqltext)

do until Results.eof
Response.Write(Results(&quot;Cost&quot;))
Results.movenext
loop
%>

</form>
</body>
</html>

Anything that is not HTML should be inside the <% ASP header and %> end of asp...

Emagine Solutions, Inc.
 
umm remove this fromt he page

'Connects to the Access driver and Access database in the Inetpub directory where the database is saved
strProvider = &quot;Driver={Microsoft Access Driver (*.mdb)}; DBQ=E:\Inetpub\'Creates an instance of an Active Server component
set objConn = server.createobject(&quot;ADODB.Connection&quot;)
'Opens the connection to the data store
objConn.Open strProvider
'Instantiate Command object and use ActiveConnection property to
'attach connection to Command object
set cm = Server.CreateObject(&quot;ADODB.Command&quot;)
cm.ActiveConnection = objConn


the stuff you added. Emagine Solutions, Inc.
 
Hi Hui,

i am getting the message:

Microsoft VBScript compilation error '800a0400'

Expected statement

/Test.ASP, line 10

type=Request.Form(&quot;type&quot;)


I don't understand, in your last post, are you saying to remove all the connection code? or should i remove only the comments?
ruth.jonkman@wcom.com
 
<% @Language=VBScript %>
<html>

<head>
<title>test</title>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

<%

type=Request.Form(&quot;type&quot;)

if (type = 1) then
sqltext = &quot;SELECT * FROM Car&quot;
elseif (type = 2) then
sqltext = &quot;SELECT * FROM Boat&quot;
elseif (type = 3) then
sqltext = &quot;SELECT * FROM Star&quot;
elseif (type = 4) then
sqltext = &quot;SELECT * FROM House&quot;
elseif (type = 5) then
sqltext = &quot;SELECT * FROM Computer&quot;
end if

set cnn = Server.CreateObject(&quot;ADODB.Connection&quot;)
cnn.Open &quot;driver={Microsoft Access Driver (*.mdb)};;DBQ=E:\Inetpub\
set Result = cnn.Execute(sqltext)

do until Results.eof
Response.Write(Results(&quot;Cost&quot;))
Results.movenext
loop
%>

</form>
</body>
</html>

-> try that
the connection code are at the bottom
set cnn and cnn.open.

you don't need to put your own connection codes.

hui Emagine Solutions, Inc.
 
I still keep getting the error:
Microsoft VBScript compilation error '800a0400'

Expected statement

/Test.ASP, line 12

type=Request.Form(&quot;type&quot;)


Here is my test.HTML:
<HTML>
<HEAD>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html;charset=windows-1252&quot;>
<TITLE>Query1</TITLE></Head>
<BODY>

<FORM METHOD=&quot;Post&quot; ACTION=&quot;Test.ASP&quot;>
<SELECT name=&quot;type&quot; class='box1'>
<OPTION value='1'>Car</OPTION>
<OPTION value='2'>Boat</OPTION>
<OPTION value='3'>Star</OPTION>
<OPTION value='4'>House</OPTION>
<OPTION value='5'>Computer</OPTION>
</SELECT>
<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Run Query&quot;>

</FORM>
</BODY>
</HTML>

and here is my test.asp:
<% @Language=VBScript %>
<html>

<head>
<title>test</title>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

<%

type=Request.Form(&quot;type&quot;)

if (type = 1) then
sqltext = &quot;SELECT * FROM Car&quot;
elseif (type = 2) then
sqltext = &quot;SELECT * FROM Boat&quot;
elseif (type = 3) then
sqltext = &quot;SELECT * FROM Star&quot;
elseif (type = 4) then
sqltext = &quot;SELECT * FROM House&quot;
elseif (type = 5) then
sqltext = &quot;SELECT * FROM Computer&quot;
end if

set cnn = Server.CreateObject(&quot;ADODB.Connection&quot;)
cnn.Open &quot;driver={Microsoft Access Driver (*.mdb)};;DBQ=E:\Inetpub\
set Results = cnn.Execute(sqltext)

do until Results.eof
Response.Write(Results(&quot;Cost&quot;))
Results.movenext
loop
%>

</form>
</body>
</html>

Do you know why i keep getting the error? ruth.jonkman@wcom.com
 
'type' is a reserved word.

try using the variable name, myType instead and see if that clears it up.

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top