View Full Version : Weird ASP/SQL Problem

03-06-2007, 07:23 AM
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" />

The search.asp page:

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:

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

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

Any idea why?

03-06-2007, 01:02 PM
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

03-06-2007, 01:13 PM
I ahve done that, its passing a NULL value

03-06-2007, 03:19 PM
There is a difference between NULL (no value) and the empty string to a database.
This might be part of what you're seeing.

03-07-2007, 05:55 AM
post your whole code of two pages here..