Results 1 to 7 of 7

Thread: How would i...

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    9

    How would i...

    I want to create a search box, where users can enter a name, and it searches the database and displays. the form tag is

    <form runat="server" name="form1" method="post" action="search2.asp">

    in search2.asp i put the SQL as

    Code:
    SQLString = "SELECT * FROM Clients WHERE Request.Form("surname")=surname ORDER BY clientID ASC "
    Am i doing something really silly and wrong?

    Plus, in future i'd like to create a thing, where the user can select what field he'd like to search in aswell, and advice?

    Thanks in advance
    Last edited by Bubbles_; Mar 31st, 2003 at 11:06 AM.

  2. #2
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Should be: (I thinnk)
    Code:
    SQLString = "SELECT * FROM Clients WHERE surname ='" & Request.Form("username") & "' ORDER BY clientID ASC "

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    9
    Thanks a lot !!

    Works

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    9
    the next bit...

    I have this on search.asp
    Code:
    <select name="searchtype">
    <option value="ClientID">ClientID
    <option value="surname">Surname
    <option value="age" selected>Age
    <option value="Email">Email
    </select>
    what would you type in search2.asp so that it selects that field, something like this?

    SQLString = "SELECT * FROM "' & Request.form("searchtype") & "' WHERE surname ='" & Request.Form("field") & "' ORDER BY clientID ASC "

  5. #5
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    NO,

    it's:
    Code:
    SQLString = "SELECT * FROM Clients  WHERE [" & Request.form("searchtype") & "]='" & Request.Form("field") & "' ORDER BY clientID ASC "
    
    
    if age is a numeric field then remove single quotes from sql statement. Same for ClientID.

    It's always:

    SELECT fields_to_select
    FROM table_name
    WHERE field_name = field_value
    ORDER BY field_name ASC (DESC)

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    9
    you sir...are a god !



    watch this space for more silly problems

  7. #7
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Can't wait....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width