Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts

    Question Weird ASP/SQL Problem

    Weird ASP/SQL Problem


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

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

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

    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:

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

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

    Any idea why?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    response.write the sql before excuting it. That way you know what you are asking from the database. That way you can think of a way to make the behaviour as desired
    I am the luckiest man in the world

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    911
    Thanks
    302
    Thanked 2 Times in 2 Posts
    I ahve done that, its passing a NULL value

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    There is a difference between NULL (no value) and the empty string to a database.
    This might be part of what you're seeing.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    post your whole code of two pages here..

    -SSJ


  •  

    Posting Permissions

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