PDA

View Full Version : Checking Problem... Please help


scriptblur
10-21-2002, 09:00 AM
Hi guys...
Please help me... i have stuck in this problem for a long time...

Currently i am doing an editing function, however problem arise...
i wanted to check first before doing editing, check if it is the same
user by using StrComp to compare the "UserID" that is passed in by form with the database "UserID", this checking succeed. But the check for blank field in the database has failed... it kept giving NO!!!!
Why????

<% @ Language=VBScript %>
<% Option Explicit %>

<%

Dim conn,rs,sql
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("database.mdb"))

set rs=Server.CreateObject("ADODB.Recordset")

sql = "SELECT UserID, Avail FROM Zones WHERE Week = "&request.form("weeks")&" AND Day = '"&request.form("days")&"' AND Character = '"&request.form("location")&"' AND Starttime AND Endtime BETWEEN "&request.form("times")&" AND "&request.form("timesno")&""
rs.Open sql, conn

Session("Week") = Request.Form("weeks")
Session("Day") = Request.Form("days")
Session("Character") = Request.Form("location")
Session("Starttime") = Request.Form("times")
Session("Endtime") = Request.Form("timesno")

if (StrComp(rs("UserID"),Session("UserID")) = 0 or StrComp(rs("UserID"),"""")= 0) then
Response.Redirect"delete_edit.asp"
else
if (StrComp(rs("UserID"),"") = 0 AND StrComp(rs("Avail"),"") = 0) then
Response.Write "Yes"
else
Response.Write "No"
end if
end if
%>

glenngv
10-21-2002, 11:02 AM
you can easily debug to see what values are retrieve in the database by writing out the values first before the comparison like this:

response.write "ID from DB: " & rs("UserID") & "<br>"
response.write "ID from Session: " & session("UserID") & "<br>"
response.write "Avail: " & rs("Avail") & "<br>"
response.end

scriptblur
10-22-2002, 04:58 AM
hi glenn, thank u

I have try what you have said.... however my problem is why can't this VB script statement work???

if (StrComp(rs("UserID"),"") = 0 AND StrComp(rs("Avail"),"") = 0) then
Response.Write "Yes"
else
Response.Write "No"


it kept giving me "No" when the UserID and Avail in the database are blank, it should print "Yes".

whammy
10-22-2002, 05:21 AM
Do you mean to use the Len() function? i.e.:

If Len(whatever) = 0 Then

:confused:

glenngv
10-22-2002, 05:25 AM
are you sure they are blank or maybe they are NULL. it's different.
to test if it is null:

if isNull(rs("UserID")) then response.write "NULL user id"

scriptblur
10-22-2002, 07:59 AM
hi... what if it is a null?? how to do the checking for that???
can u please teach me... thank,,,,,

glenngv
10-22-2002, 08:28 AM
i've shown a sample in my previous post.

userID = rs("UserID")
avail = rs("Avail")

if (isNull(userID) or userID="") and (isNull(avail) or avail="")
Response.Write "Yes"
else
Response.Write "No"
end if

scriptblur
10-22-2002, 09:29 AM
hi glenn.. thank u very much.... i had solve the problem using your method... however.... what is the diff btw blank and null???

glenngv
10-22-2002, 10:46 AM
blank is an empty string, null is completely nothing

http://www.asptechniques.com/content.asp?a=co&cID=535

try running this to see the difference:

str1=null
str2=""
response.write "length of empty:" & len(str2) & "<br>"
response.write "length of null:" & len(str1)


maybe somebody can explain better.

whammy
10-23-2002, 12:28 AM
I can't explain it any better than that.

scriptblur
10-24-2002, 04:07 AM
ok thank u very much i guess i know the diff.....