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.
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
<input type= "submit">
If Request.Form("c1") = "ON" then
S1 = Request.Form("t1")
S1 = "India"
If Request.Form("c2") = "ON" then
S2 = Request.Form("t2")
S2 = "EA"
If Request.Form("c3") = "ON" then
S3 = Request.form("L1")
S3 = "EA"
set conn = server.createobject ("adodb.connection")
set rs=conn.execute("Select * from userlist where country = 'india' ")
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