473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can't display image from mySQL database

Query.asp
Expand|Select|Wrap|Line Numbers
  1. <%@ LANGUAGE="VBSCRIPT" %>
  2. <!-- #include file="../../includes/dbconn.asp"-->
  3. <%
  4. dim MyRs, sqlstr, MyConn
  5.  
  6.    Response.Expires = 0
  7.    Response.Buffer = TRUE
  8.    Response.Clear
  9.    Response.ContentType = "image/gif"
  10.  
  11.   Set MyConn = Server.CreateObject("ADODB.Connection")
  12.   MyConn.Open dbConn
  13.   Set MyRs = Server.CreateObject("ADODB.Recordset")
  14.  
  15.       sqlstr="select img from img"
  16.       MyRs.Open sqlstr, MyConn, adOpenKeyset, adLockOptimistic
  17.        Response.BinaryWrite MyRs("img")
  18.       Response.End
  19.  
  20. MyRs.Close
  21. MyConn.Close
  22.  
  23. set MyRs=nothing
  24. set MyConn= nothing
  25. %>
Main.asp
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.    <HEAD><TITLE>Display Image</TITLE></HEAD>
  3.    <BODY>
  4.    This page will display the image New Moon Books from a SQL Server
  5.    image field.<BR>
  6.    <IMG SRC="Query.ASP">
  7.    </BODY>
  8.    </HTML>
why can't display, really dunno what to do
Dec 2 '07 #1
7 4197
JamieHowarth0
533 Expert 512MB
Hi Alex,

Try changing the SQL query as follows:
Expand|Select|Wrap|Line Numbers
  1. SELECT [img].[img] FROM [img];
SQL does not like parent and child objects (the child/ren field/s of the parent table) to have identical names as it can confuse things.
The square brackets should act as field name delimiters so the first lot of text in square brackets identifies the table name, followed by the field name.

Failing that, rename the image binary data field to something different, for example ImgData and let us know how you get on.

You also were calling your SQL statement twice - using the Open command with a SQL string as a parameter automatically executes the SQL and returns the results. I removed the line where you used MyRs.Execute.

And finally, simple question - but do you have any image data stored in your database at present?

Best regards,

medicineworker
Dec 2 '07 #2
Hi Alex,

Try changing the SQL query as follows:
Expand|Select|Wrap|Line Numbers
  1. SELECT [img].[img] FROM [img];
SQL does not like parent and child objects (the child/ren field/s of the parent table) to have identical names as it can confuse things.
The square brackets should act as field name delimiters so the first lot of text in square brackets identifies the table name, followed by the field name.

Failing that, rename the image binary data field to something different, for example ImgData and let us know how you get on.

You also were calling your SQL statement twice - using the Open command with a SQL string as a parameter automatically executes the SQL and returns the results. I removed the line where you used MyRs.Execute.

And finally, simple question - but do you have any image data stored in your database at present?

Best regards,

medicineworker

I have fields with named id (int),img (BLOB) in my table called img.It is correct? and I manually insert a picture through the MySQL yog(db administration interface)
Dec 2 '07 #3
JamieHowarth0
533 Expert 512MB
Hi Alex
I have fields with named id (int),img (BLOB) in my table called img.It is correct?
As mentioned previously, add the square braces and the full-stop, and rename the "img" field to ensure that MySQL is reading the query correctly, otherwise it will be interpreted as "SELECT myTable FROM myTable" - as we all know you can't select a table from a table, so by definition it's not correct.

medicineworker
Dec 2 '07 #4
pbmods
5,821 Expert 4TB
Heya, Alex.

The exciting part of computer programming is getting a machine that does exactly what you tell it to do... to do what you want it to do.

You set up your table correctly, and your query looks right... but the server is misinterpreting it. Try adding the proper delimiters to eliminate the possibility of ambiguity in your query.
Dec 2 '07 #5
Hi Alex

As mentioned previously, add the square braces and the full-stop, and rename the "img" field to ensure that MySQL is reading the query correctly, otherwise it will be interpreted as "SELECT myTable FROM myTable" - as we all know you can't select a table from a table, so by definition it's not correct.

medicineworker
Display.asp
Expand|Select|Wrap|Line Numbers
  1.       <HTML>
  2.          <HEAD><TITLE>Display Image</TITLE></HEAD>
  3.          <BODY>
  4.          <IMG SRC="Query.asp">
  5.          </BODY>
  6.          </HTML>
Query.asp
Expand|Select|Wrap|Line Numbers
  1.       <%@ LANGUAGE="VBSCRIPT" %>
  2.       <!-- #include file="../../includes/dbconn.asp"-->
  3.       <%
  4.       dim MyRs, sqlstr, MyConn
  5.  
  6.          Response.Expires = 0
  7. Response.Buffer = TRUE
  8. Response.Clear
  9. Response.ContentType = "image/gif"
  10.  
  11.         Set MyConn = Server.CreateObject("ADODB.Connection")
  12. MyConn.Open dbConn
  13. Set MyRs = Server.CreateObject("ADODB.Recordset")
  14.  
  15. sqlstr="select file from img"
  16. MyRs.Open sqlstr, MyConn, adOpenKeyset, adLockOptimistic
  17.              Response.BinaryWrite MyRs("file")
  18. Response.End
  19.  
  20.       MyRs.Close
  21.       MyConn.Close
  22.  
  23.       set MyRs=nothing
  24. set MyConn= nothing
  25.       %>
My table is called img with fields id(int) and file (blob) . It's correct? why i still can't display.Thanks
Dec 2 '07 #6
848lu
37
hi, i was wandering....can you match the picture name with table primary key, so for my project i want to display a picture which also mathces with the primary key with a record, and display it on the screen, automatically.

as when users click the menu from pictures menu, the code automatiicaly does this, and beside the picture i want to display the record details.


thanks....
Dec 29 '07 #7
848lu
37
ok i guess nobody knows how to do it
Jan 4 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Alper Adatoz | last post by:
Hi, i have a little problem. i hope u guys give me a clear solution (: db: mssql i just want to put jpeg file to the image field at the mssql db. and after that i want to call it back..
0
by: Dan Anderson | last post by:
I have created a BLOB field to store images. Is there any way to embed them within HTML with something like: <image start: jpeg> </image> Thanks in advance, Dan
2
by: david | last post by:
Hi, I have asp pages running from a MySQL database. I have placed a path in the required field (although not quite sure on the correct format). My asp page is just displaying the text path...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
1
by: Objectifnet | last post by:
What I really want to do is to be able to link two pages together using an ID, The table involved displays an image stored on the File Server that has the image details stored in the Database called....
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
4
by: tanyali | last post by:
my .png files r stored as a blob in MySql, I wanna to display them out in php through a web browser. this is part of code (in php): ---after connect to database , $dbQuery=" select name,...
48
by: mirianCalin | last post by:
i am doing a site for appliance center.. i need to display all the products that the company offers, but my problem is that i cant display ALL the images in my database.. the first entry on the...
6
by: msmjsuarez | last post by:
how can i display both image and other information in the web page using php? i'm using mysql database. I do displaying the image only but i want to display both other information from the database...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.