Click to See Complete Forum and Search --> : Facing this problem in asp & sql server 200(I want to dispaly images stored in the )


yoyali
05-04-2006, 02:56 AM
Hello every body ,
I'm facing this problem in my asp code. I have inserted the image i want in the db and i guess it worked fine coz the field have the value <binary>. but my problem is how to display this image.Response.write(rs("image_value") didn't work at all . So please if any one have any idea of how to do it then tell me . If there is any objects needed to be created tell me for I know nothing and i'm new in this field .
plz if u kow any idea respond quick for my work stop at this point

thanx alot for being interested,
Yoya

russell
05-04-2006, 12:59 PM
Response.BinaryWrite imgDataHere

yoyali
05-04-2006, 01:23 PM
Response.BinaryWrite imgDataHere

Thank u russell for trying to help me, but when i tried this it gave me this error message (An unhandled data type was encountered.
).can u tell me what is wrong with it plz.thank u once again.thanks again
yoya

russell
05-04-2006, 02:29 PM
post the code and we'll have a look-see

yoyali
05-04-2006, 02:35 PM
thank u for being interesed,
Here I'm inserting the image into Db and then displaying it
<%
sql="insert into advertisment (adv_image,adv_user) values('"&image&"','"&userid&"')"
set rs=conn.Execute (sql)
Response.Write("added")
sql="select * from advertisment where adv_user='"&userid&"'"
set rs=conn.Execute (sql)
Response.ContentType = "image/jpg"
Response.BinaryWrite rs("adv_image")
%>
but i wan't to say that i'm reseving the value ot image br Request.QueryString("image") for it is in a form with method= "get"
is this aproblem .
butting in mind that the db field is not null.
thank u russell

russell
05-04-2006, 02:52 PM
Can't mix writing modes in the same script. Either all .BinaryWrite or all .Write.

In your code snippet, comment out the Response.Write ("added")

Check out this sample code

<%
Dim st
Dim im

im = Server.MapPath("/images/myImage.gif")

Set st = Server.CreateObject("ADODB.Stream")
st.Type = 1
st.Open

st.LoadFromFile im
'Response.Write "ok"
Response.BinaryWrite st.read
Response.Write "ok"

Set st = nothing
%>
uncomment out the first response.write "ok" and the image fails to display. Leave as is and the last Response.Write "ok" fails.

russell
05-04-2006, 02:56 PM
You are almost always better off storing the path to an image in a varchar field than storing the image data itself in your db

yoyali
05-04-2006, 03:01 PM
i'll be litle bit anoying ,
wold u tell me how to get the pathe of the image

russell
05-04-2006, 03:38 PM
what are you doing, letting users upload images? if so, you'll need to save them somewhere on the server...

else if u must put 'em in a db, you need to use only one type of write method at a time when displaying

yoyali
05-04-2006, 04:01 PM
Hi Russell,
I forgot to tell u that this image is not entered by me ,it is entered by the user,so i don't know it's path.if there is any way to get this path plz tell me >
i'll guve u my code and see what do u say about it
here is the "GET" form i where the user submit his image:
<form action="user.asp" method="get">
<table width="100%" border="1">
<input type="hidden" name="flag" value="add">
<input type="hidden" name="act" value="addadv">
<input type="hidden" name="id" value="<%=session("session_id")%>">
<input type="hidden" name="loginas" value="admin">
<input type="hidden" name="userid" value="<%=session("user_id")%>">
<%

dim adv_row,adv_column,i,e,col_count
For i = 1 to 5
session("row")=i
Response.Write "<tr>"
col_count=1
For e =1 to 4
Response.Write "<td><input type='file' name='"&image&"' ></td>"
col_count=col_count+1

Next
Next
Response.Write("</tr>")
%>
</table>
<center>
<table>
<tr>
<td>
<center><input type="submit" value="SUBMIT"></center>
</td>
<td>
</td>
</table>
</center>
</form>
from this i get the image and the user id and insert it in the DB by this code:
<%
end if
elseif act="addadv" then

dim image
image=Request.QueryString("image")
sql="insert into advertisment (adv_image,adv_user) values ('"&image&"','"&userid&"')"
set rs=conn.Execute (sql)
sql="select * from advertisment where adv_user='"&userid&"'"
set rs=conn.Execute (sql)
Response.ContentType = "image/jpg"
Response.BinaryWrite rs("adv_image")
%>
and trying to display this image but as i told u it didn't work even afteri deleted the response.write i even tried to submit the form to an other page with this code only nothing after or before except the included DB connection file>
So plz if u have time tell me how to do it by getting the path of the image or by any other way . i know i'm asking alot but i know u 'll help me >
Thanks alot<
yoya

yoyali
05-04-2006, 04:03 PM
yes it 's exactly what i'm doing . leting users upload images, put i don't know how to do it right.

russell
05-05-2006, 10:30 AM
ok, you have a lot you need to do to get this working.

your form needs to be multi-part.
your method needs to be post
you need to write code to handle multi-part data

To get the image data, you need to read the post values with a Binary read -- which rules out any references to Request.Form or Request.QueryString

Check out this article (http://www.asp101.com/articles/jacob/scriptupload.asp) on ASP101. 4GuysFromRolla (http://www.4guysfromrolla.com/) probably has a pure ASP file upload class too.

What you do is use BinaryRead to save the file on your web server or network (or in your database). Then you can reference it by the unc path on your network (or pull it from your db).

Check out the code on ASP101 and see if that gets you going.

yoyali
05-05-2006, 01:34 PM
thank u Russell for helping me , i'll check it out .
but I want to ask u this can i send u private messages if i need any thing , if it is ok with u ?

russell
05-05-2006, 01:58 PM
no probem, but better to post your questions on the forum so everyone can benefit from anything learned. for every question posted there are probably 100 people out there wondering the same thing.