-
variables in select statements
I hope someone can help me. I am trying to construct a search page to search
a database. I want to give people the option to use one or more of several
search categories. I have attached the code so you can see what I am trying
to do. I want to let people use check boxes to control which criteria they
want to use to search. To do this, I think I need to be able to pass variables
into the SELECT statement. I am having a very difficult time getting the
syntax correct. Right now, I am just trying to get the syntax to work for
the first field. Eventually, I want to expand the search form to six fields.
I have several books to go by, but the syntax seems to be a little different
in each, and I can't get it to work. I don't have much experience with ASP
or VBScript, and so I would appreciate any help anyone could give me.
Thank You,
Ken
Here part of the code that I have. This is not totaly the way I want the
final version to be, but I am trying to figure out a litle piece at a time.
As you can see, I am evaluating the check box to determine whether or not
to use the field in the search. If the box is checked, I will use what the
user enters. If the box is not checked, I have set the variable to equal
a set value. (Eventually, I want that alternate value to be a wild card or
something that will return all records so that if the form is submitted while
totally blank, it will return all records. My idea is to use the values
entered by users to narrow the search.) The select statement works as it
is written now because I have entered a specific country, but it does not
work if I try to enter the variable S1. Can someone please suggest what
I can do to get the select statement to work using variables passed to it?
<form method= "post">
<input type= "checkbox" name= "c1" value= "ON"><b>Country:</b>
<input type= "text" name= "t1"><br>
<input type= "checkbox" name= "c2" value= "ON"><b>System:</b>
<input type= "text" name= "t2"><br>
<input type= "checkbox" name= "c3" value= "ON"><b>Status:</b>
<select name= "L1">
<option name= "Running">Running
<option name= "Sold">Sold
<option name= "EA">EA
</select><br>
<input type= "submit">
</form>
<%
DIM c1
DIM c2
DIM c3
DIM t1
DIM t2
DIM L1
DIM S1
DIM S2
DIM S3
If Request.Form("c1") = "ON" then
S1 = Request.Form("t1")
Else
S1 = "India"
End If
If Request.Form("c2") = "ON" then
S2 = Request.Form("t2")
Else
S2 = "EA"
End If
If Request.Form("c3") = "ON" then
S3 = Request.form("L1")
Else
S3 = "EA"
End If
set conn = server.createobject ("adodb.connection")
conn.open "NewDSN"
set rs=conn.execute("Select * from userlist where country = 'india' ")
%>
</body>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks