Skip to main content
Inspiring
July 9, 2006
Question

only display image if filename in database

Hi,
I'm trying to write the code to only display an image if there is a file name in the database for the image (i.e. if there is no image for the item, no image tags are written to the page etc)

Heres what I have:

<code>

<%
Dim bookImage
bookImage = (rsBooks.Fields.Item("book_imageURL").Value)
If bookImage > 1 then
Response.Write("<img src='i/bookCovers/<%=bookImage%>'/>")
Else
End If

%>

</code>

I'm getting the following error:

Unterminated string constant

/index.asp, line 197

Response.Write("<img src='i/bookCovers/<%=bookImage
---------------------------------------------------^

I can't figure the problem.

Appreciate any advice.
This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Participating Frequently
July 10, 2006
You are already in a server code block when you try and call the <%=bookImage%> this is why it fails. Change that line to this...

Response.Write("<img src='i/bookCovers/" & bookImage & "'/>")
Translate
jsltdAuthor
Inspiring
July 13, 2006
Thanks for your repsonse, that worked perfectly.

I'm now in trouble with the same thing, I can't figure out what"s what !:

<%
Dim spanishReview
spanishReview = (rsBooks.Fields.Item("book_spanish_title").Value)
If spanishReview > "" then
Response.Write("<A HREF='ReviewSpanish.asp?<%= Server.HTMLEncode(MM_keepURL) & MM_joinChar(MM_keepURL) & ""book_id="" & rsBooks.Fields.Item(""book_id"").Value %>'>Revisi&oacute;n espa&ntilde;ola &raquo;</A>")
else
End If
%>

I've tried to put the double quotes in the right places, but can't get it right. Any help much appreciated.

Translate
Participating Frequently
July 14, 2006
LOL, I know you read my original reply but did you actually take it in? You're making the same mistake in this new bit of code as you were making in the first one.

Apply the same principle, take out the server tags as you are already coding IN a script block.
Translate