1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Rep Power

    Unhappy 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.

  2. #2
  3. superficial
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Peterborough, England
    Rep Power
    Quite a lot to ask really, don't you think?

    To start with, you need a html form that looks like this
    <form method="post">
    <input type="checkbox" name="searchchoice" value="holidays" />
    <input type="checkbox" name="searchchoice" value="cars" />
    <input type="checkbox" name="searchchoice" value="monkeys" />
    and an asp page that does something like.....

    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>"
    you'd need something in place that makes sure they only select one choice, otherwise it will screw the SQL statement up.......

    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.

IMN logo majestic logo threadwatch logo seochat tools logo