Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - if database field empty.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

if database field empty.

 Post Reply Post Reply
Author
Badaboem View Drop Down
Senior Member
Senior Member


Joined: 12 April 2002
Location: Netherlands
Status: Offline
Points: 600
Post Options Post Options   Thanks (0) Thanks(0)   Quote Badaboem Quote  Post ReplyReply Direct Link To This Post Topic: if database field empty.
    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?

 

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Badaboem View Drop Down
Senior Member
Senior Member


Joined: 12 April 2002
Location: Netherlands
Status: Offline
Points: 600
Post Options Post Options   Thanks (0) Thanks(0)   Quote Badaboem Quote  Post ReplyReply Direct Link To This Post 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)%></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?

 

 

Back to Top
fernan82 View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 17 November 2002
Location: United States
Status: Offline
Points: 362
Post Options Post Options   Thanks (0) Thanks(0)   Quote fernan82 Quote  Post ReplyReply Direct Link To This Post 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."

Edited by fernan82
FeRnAN
Back to Top
Badaboem View Drop Down
Senior Member
Senior Member


Joined: 12 April 2002
Location: Netherlands
Status: Offline
Points: 600
Post Options Post Options   Thanks (0) Thanks(0)   Quote Badaboem Quote  Post ReplyReply Direct Link To This Post 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 .

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.