February 21st, 2003, 10:41 AM
Using information from a form to search a database
I'm trying to use information that a user enters into an HTML form to search a database. For example, if a user clicks on a check box stating their interests are 'holidays' then this information needs to be used to search the database for entries that match, ie the entry has a category that states it is about holidays.
The entries in the database are linked to pictures that will then be loaded onto a website. I need to use ASP for this as well but have got completely stuck and don't know where to start, therefore any help is greatly appreciated.
February 24th, 2003, 10:05 AM
Quite a lot to ask really, don't you think?
To start with, you need a html form that looks like this
and an asp page that does something like.....
<input type="checkbox" name="searchchoice" value="holidays" />
<input type="checkbox" name="searchchoice" value="cars" />
<input type="checkbox" name="searchchoice" value="monkeys" />
you'd need something in place that makes sure they only select one choice, otherwise it will screw the SQL statement up.......
dim c, r, s
set c = createobject("adodb.connection")
set r = createobject("adodb.recordset")
c.connectionstring = (connectionstring needed here)
c.provider = "Microsoft.Jet.OleDB.4.0"
s = "select * from wherever where something like '" & request.form("searchchoice") & "'"
Set r = c.execute(s)
while r.eof = false
response.write r.fields(0) & "<br>"
response.write r.fields(1) & "<br>"
response.write r.fields(2) & "<br>"
If you selected "Holidays" then the SQL would be select * from wherever where something like 'holidays' and if the other choices are picked, holidays would be replaced with the respective choice. then a simple loop will write out all rows that match the SQL statement.
I'd recommend a book on ASP!
By the way, that won't work by itself but it demonstrates what you need to do, in a crude way.
Last edited by Utopia; February 24th, 2003 at 10:10 AM.