Click to See Complete Forum and Search --> : Loading pictures into a database and displaying with ASP code
Hello,
I need to display a picture on my asp page, i am using a Access database i can get all the other information to display but i am unsure how to add a picture in? i tryed using a hyperlink but it didnt work? Any idea's?
Thanks Shaun
Upload the picture to your webserver, then in your database, keep the filename and width, height and alt, then, get the filename from the db and display that:
<img src="<%=putfilenamehere%> width="<%=putwidthhere%>" height="<%=putheighthere%>" alt="<%=putalthere%>"/>"
http://www.blythnet.co.uk/yt/asp/motobike.asp
One question what is ment to be in this part of the code: "<%=putalthere%>"
This is my code atm
<html><style type="text/css">
<!--
body {
background-color: #FFFFCC;
}
-->
</style>
<Body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "motobike"
set rs=Server.createObject("ADODB.Recordset")
rs.open "select * from motobikes", conn
%>
<Table width= "80%" border="1" align="center" bgcolor="#A4BBDD">
<tr>
<%Do until rs.EOF
<!--For each x in rs.fields%>
<tr><td><div align="center">
<% response.write rs("make")&"<br>"%>
</div></td></tr>
<tr> <td><div align="center">
<%response.write rs("model")&"<br>"%>
</div></td>
<img src="<%=picture_FN%> width="<%=400>" height="<%=500>" alt="<%=500>"/>"
<td></tr>
<%rs.movenext
Loop%>
</Table>
</Body>
</html>
Terrorke
04-25-2006, 06:11 AM
"<%=putalthere%>" means you put the value of your databasefield that contains your alt text of your picture into the html tag.
Make sure you have all the variables of your html tag stored into your databasetable.
Terrorke
04-25-2006, 06:15 AM
Sorry sametime we were posting I guess.
On line 29 you have a tag <td>. Replace this with </tD>. Or put a second <td> tag on your line 27 (I guess) Because you have 2 </td> and only 1 <td> tags at this moment
<img src="<%=picture_FN%> width="<%=300>" height="<%=400>" alt="<%=500>"/>"
Im still getting an error on this line :(
Terrorke
04-25-2006, 08:20 AM
Try leaving the double quote at the and of the line
Maybe that helps
Sorry im a bit new to this :o
Got it to display this now: (some reason it cant always find the database)
http://www.blythnet.co.uk/yt/asp/db2.asp
The URL for the picture that i am trying to load is
http://www.blythnet.co.uk/yt/asp/car.jpg
and the picture address that im getting when i go on asp is
http://www.blythnet.co.uk/yt/asp/width=
Thanks
Terrorke
04-25-2006, 08:28 AM
This is starting to look at a chat session :)
It seems to me that your source of the image isn't been set properly.
The problem is within your double quotes.
Try using this :
<img src="<%=picture_FN%>" width="<%=400>" height="<%=500>" alt="<%=500>"/>
That should do it!
This is my database table i dont have anything else in the access file
http://www.blythnet.co.uk/yt/asp/db.jpg
This code
<img src="<%=picture_FN%> width="<%=300%>" height="<%=400%>" alt="<%=500%>"/>
Will display This:
http://www.blythnet.co.uk/yt/asp/d1.jpg
and this code
<img src="<%=picture_FN%>" width="<%=400>" height="<%=500>" alt="<%=500>"/>
Displays an error on line 29 (the line of the above code)
This is all my code atm:
<html><style type="text/css">
<!--
body {
background-color: #FFFFCC;
}
-->
</style>
<Body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "motobike"
set rs=Server.createObject("ADODB.Recordset")
rs.open "select * from motobikes", conn
%>
<Table width= "80%" border="1" align="center" bgcolor="#A4BBDD">
<tr>
<%Do until rs.EOF
<!--For each x in rs.fields%>
<tr><td><div align="center">
<% response.write rs("make")&"<br>"%>
</div></td></tr>
<tr> <td><div align="center">
<td><%response.write rs("model")&"<br>"%>
</div></td>
<img src="<%=picture_FN%> width="<%=300%>" height="<%=400%>" alt="<%=500%>"/>
</td></tr>
<%rs.movenext
Loop%>
</Table>
</Body>
</html>
Sorry about this :o
Terrorke
04-25-2006, 08:47 AM
Ok now I see your mistake
Your are just putting the variable picture_FN into the src. but it hasn't got any value.
Try using this (hopefully this will work) :
<img src="<%=rs("picture_FN")%>" width="<%=300%>" height="<%=400%>" alt="<%=500%>"/>
Sorry my fault.
:D :D :D :D
Thanks mate!! :D That has worked fine :) it was my fault i should have more of a clue what im doing :p
Thanks again :)
Terrorke
04-25-2006, 08:57 AM
:D
No problem. Happy I could (eventually) help :D