Print Page | Close Window

if database field empty.

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=6830
Printed Date: 31 March 2026 at 4:39pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: if database field empty.
Posted By: Badaboem
Subject: if database field empty.
Date Posted: 29 October 2003 at 10:55am

I'm trying to incorperate some forum features into a gallery on my website.

So far I've managed to automatically fill in profile information such as user name, email and url into the gallery database.

Since this will only happen with newly entered images I would like to check if the database fields are empty or not...if they are empty use if/else to show the text ''not available''.

I know how to do this with strings, but not with the code below.

<%=(rsPic.Fields.Item("PIC_URL").Value)%>
.

How do I go about checking if a field is empty or not?

 




Replies:
Posted By: ljamal
Date Posted: 29 October 2003 at 11:12am
if RecordSet("FieldName")= "" or IsNull(RecordSet("FieldName")) then
Reponse.Write "Not Available"
else
Response.Write RecordSet("FieldName")
end if

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: MorningZ
Date Posted: 29 October 2003 at 11:51am

i use a function for that.. it's:

Function CstrNull(i_val)
     CstrNull = Cstr(i_val & "")
End Function

and then your code would be

if CstrNull(RecordSet("FieldName") <> "" then
      Response.Write RecordSet("FieldName")
else
      Reponse.Write "Not Available"
end if

maybe it's just me, but i HATE checking for NULL and empty string seperately, that function has been my savior for 4 years now :-)



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Badaboem
Date Posted: 29 October 2003 at 6:08pm

Thanks guys! That worked like a charm. 

I'm left with one issue I can't work out. I've used if / else if to see if the user is loged in.

If the user is not loged in and an email address has been entered in field, show text: login to view.

If the user is not loged in and an email address has not been entered in field, show text: Not available.

If the user is loged in and an email address has not been entered in field, show text: Not available.

<%
If lngLoggedInUserID = 2  and CstrNull(rsPic.Fields.Item("PIC_URL")) <> "" Then
Response.Write "Login to view" & "."
Else if IngLoggedInUserID = 2 and CstrNull(rsPic.Fields.Item("PIC_URL")) < "" then
Response.Write "not available" & "."
Else if ingLoggedInuserID <> 2 and CstrNull(rsPic.Fields.Item("PIC_URL")) < "" then
Response.Write "not available" & "."

%>
                 <%else%>
                 <font color="#800000"><a href="mailto:<%=rsPic.Fields.Item"PIC_EMAIL".Value%>"><%=(rsPic.Fields.Item("PIC_EMAIL").Value)%> mailto:<%=(rsPic.Fields.Item("PIC_EMAIL").Value)%>"> ;<%=(rsPic.Fields.Item("PIC_EMAIL").Value)%></a> </font>
                 <%end if%><%end if%>

It doesn't seem to understand that it should show ''not available'' when a user isn't loged in and an email does not exist in the database field. It simply shows no warning text at all.
Same issue with a loged in user and no email address in the database field.

the red lines are causing trouble.

What am I doing wrong here?

 

 



Posted By: fernan82
Date Posted: 29 October 2003 at 8:36pm
Change the less than sign to equal,

Else if IngLoggedInUserID = 2 and CstrNull(rsPic.Fields.Item("PIC_URL")) = "" then
Response.Write "not available" & "."

That way if the user is a guest and the field PIC_URL is null it'll display Not Avail...

It don't look like your checking for an email though.... is PIC_URL and email..?

<edit> Why you write "not available" & "." ?, wouldn't be simpler to just write: "not available."

-------------
FeRnAN
http://www.danasoft.com/">


Posted By: Badaboem
Date Posted: 30 October 2003 at 3:28am

Originally posted by fernan82 fernan82 wrote:




It don't look like your checking for an email though.... is PIC_URL and email..?

Thanks fernan. You are right. It's been late yesterday, but the url field was empty as well...The result of it not working was the same .

 




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net