Image Display w/ASP and SQL

Cinnamon
06-21-2002, 02:01 PM
I had to do some rearranging to get my ASP code working properly with my database. I was able to display an image that corresponds to a record number. After I split the SaveNow and Preview into subroutines my image will not longer display. I'm having an awful time figuring this out. I appreciate any help I can get. Thanks.

Cinnamon

<%@ Language=VBScript %>
<%
If Request.QueryString("bSave")="True" Then
SaveNow
else
Preview
End if
%>

<%
Sub SaveNow()
Response.Write "save codehere"
end sub
%>

<%
Sub Preview()
Dim cnnDatabase, rstDatabase, dtbDatabase

SearchThis = CLng(Request.QueryString("iRecordId"))
Response.Write(SearchThis)
If IsNumeric(SearchThis) Then

cnnDatabase = "Driver=SQL Server;server=DIGITAL;database=gen_cards;uid=cinnamon;pwd=sinnamon"
Set rstDatabase=Server.CreateObject("ADODB.Recordset")
dtbDatabase = "SELECT * FROM Cards WHERE [unique]=" & SearchThis & ";"
rstDatabase.Open dtbDatabase, cnnDatabase, 3, 3

If NOT rstDatabase.EOF Then
ImagePath = rstDatabase.Fields("SQLpath")
Response.Write rstDatabase.Fields("entry")

Else
Response.Write "Record not found"
End If

Else
Response.Write "Invalid input"
End If
end sub
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 2</title>
</head>
<body>
<img
src = ".<%= ImagePath %>"
width = "575"
height = "425"
/>
<br>
<form action="new_page_2.asp?bSave=True" method="post">
Enter index information:
<input type="text" name="Cindex"><br><br>
<input type="submit" value="Submit">
</form>
<p>

</body>
</html>

Derek Stone
06-21-2002, 03:39 PM
When the page loads in your browser select View --> Source and scroll down to your image tag. Is it displaying the correct path to your image?
Check that out and let us know.

Good Luck
-CL

Cinnamon
06-21-2002, 04:37 PM
Ok I checked the source.
My code is:
src = ".<%= ImagePath %>"

When I view the source...
src = "."

Which explains why it's not displaying the image. Now I juts have to figure out what went wrong. If anyone has a clue let me know!

Cinnamon

Rezner
06-21-2002, 05:26 PM
This is most likely because the conditional statement is not being met, so the ImpagePath variable is not being initialized: If NOT rstDatabase.EOF Then
ImagePath = rstDatabase.Fields("SQLpath")
Response.Write rstDatabase.Fields("entry")

Else
Response.Write "Record not found"
End IfThis is to say that the rstDatabase is at the end of the file.

Cinnamon
06-24-2002, 12:12 PM
Ok that makes sense IF the condition was not being met. However, the field "entry" does display for the correct record. Therefore the condition must be getting met. I just can't figure out why the image won't display. The variable gets set but somewhere it loses the contents of the variable.

Thinker
06-24-2002, 12:34 PM
In the code you posted, ImagePath is set in a sub, but I can't see
anywhere it is declared. If not declared anywhere, it is possible
its scope is just in the Preview() sub and when you reference it
outside Preview(), it is just a new variable.

Robby
06-24-2002, 06:48 PM
Change the....

sub Preview ()

end sub

TO...

function Preview()

'somewhere after you establish the ImagePath value, do this

Preview = ImagePath
End function


And call it this way...

If Request.QueryString("bSave")="True" Then
SaveNow
else
dim strSomePic
strSomePic = Preview
End if

Cinnamon
06-26-2002, 12:27 PM
This little problem has me so frustrated. But I'm sure that eventually it will work out. Anyway, I did what you suggested in the previous post. Now I'm getting an error message:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ';'.

/myweb/new_page_2.asp, line 30

That is the SELECT line from the Preview function. I changed the line to this:
dtbDatabase = "SELECT * FROM Cards WHERE [unique]=" & SearchThis

and got another snytax error for the "&". So I removed it and got a snytax error for the "=".

Cinnamon

<%@ Language=VBScript %>
<%
If Request.QueryString("bSave")="True" Then
SaveNow
else
Dim strSomePic
strSomePic = Preview
End if
%>

<%
Sub SaveNow()
cnnDBEdit = "Driver=SQL Server;server=DIGITAL;database=gen_cards;uid=cinnamon;pwd=sinnamon"
Set rstDBEdit=Server.CreateObject("ADODB.Connection")
dtbDBEdit = "UPDATE Cards SET entry=" & Cindex & "WHERE [unique]=" & SearchThis & ";"
rstDBEdit.Open cnnDBEdit
set rstDBupdate=rstDBedit.Execute(dtbDBEdit)
end sub
%>

<%
function Preview()
Dim cnnDatabase, rstDatabase, dtbDatabase, ImagePath

If IsNumeric(SearchThis) Then

cnnDatabase = "Driver=SQL Server;server=DIGITAL;database=gen_cards;uid=cinnamon;pwd=sinnamon"
Set rstDatabase=Server.CreateObject("ADODB.Recordset")
dtbDatabase = "SELECT * FROM Cards WHERE [unique]=" & SearchThis & ";"
rstDatabase.Open dtbDatabase, cnnDatabase, 3, 3

If NOT rstDatabase.EOF Then
ImagePath = rstDatabase.Fields("SQLpath")
Response.Write rstDatabase.Fields("SQLpath")
Response.Write rstDatabase.Fields("entry")
Preview = ImagePath

Else
Response.Write "Record not found"
End If
Else
Response.Write "Invalid input"
End If
end function
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 2</title>
</head>
<body>

<img
src = ".<%= ImagePath %>"
width = "575"
height = "425"
/>
<br>
<form action="new_page_2.asp?bSave=True" method="post">
Enter index information:
<input type="text" name="Cindex"><br><br>
<input type="submit" value="Submit">
</form>
<p>

</body>
</html>

Robby
06-26-2002, 01:18 PM
it sounds like SearchThis is blank, it looks like you forgot this line of code...


SearchThis = CLng(Request.QueryString("iRecordId"))

'you are checking but not asigning to SearchThis...
If IsNumeric(SearchThis) Then

Cinnamon
06-26-2002, 01:59 PM
That was a stupid error on my part. I had been trying lots of things and negelected to put that l;ine back in. I no longer get an error message... but the image is still not displaying.

Robby
06-26-2002, 02:36 PM
Ok, if there is no error this means the function is returning something to strSomePic.

Check its' value with a response.write(strSomePic)... see what's in there.

Cinnamon
06-26-2002, 02:51 PM
The strSomePic variable does contain the correct path to the image. The problem seems to lie with the ImagePath variable..... just I was typing this a thought occured to me. Change the ImagePath variable to strSomePic. And quess what?

IT WORKED!

Thanks for all of your help. Now that they are displaying correctly I'm going to working on editing!

Robby
06-26-2002, 04:10 PM
Cool.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum