1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Weird ASP/SQL Problem

Discussion in 'C#' started by cancer10, Mar 5, 2007.

  1. #1
    Weird ASP/SQL Problem


    Consider the following HTML Form, it has a textbox and a search button.

    <form method=post action="search.asp">
    <input name="txtName" type="text" id="txtEmail" />
    <input type="submit" name="Submit3" value="Search" />
    </form>
    Code (markup):
    The search.asp page:

    select * from tbl_group_contact where userName ='"& request("txtName") &"'
    Code (markup):

    if I put this query in the search.asp page then it will search by name based on the name I entered in the textbox. But if I leave the textbox empty and click on the search button, SQL fetches all the rows from the table. If you havent noticed this before, try it now!!


    Well, this is not my problem/question. my question is if I place a combo box instead of the textbox and assign a NULL value to one of the option field like:

    <select name="txtType" id="txtType">
    <option value="" selected="selected">All</option>
    </select>
    Code (markup):

    and press the search button, then it does not fetch all the rows as it did for the empty textbox.

    Any idea why?
     
    cancer10, Mar 5, 2007 IP
  2. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This may not be the solution, but your code is wrong - only the word selected is required.

    <select name="txtType" id="txtType">
    <option value="" selected>All</option>
    </select>
     
    Garve, Mar 6, 2007 IP
  3. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Also of course your text field is called txtName but your select box is called txtType
     
    Garve, Mar 6, 2007 IP
  4. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #4
    request("txtName") should be request.Form("txtName") - also protect it and trim it.

    trim(replace(request.Form("txtName"),"'",""))
     
    ccoonen, Mar 13, 2007 IP