473,832 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't display image from mySQL database

6 New Member
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 4224
JamieHowarth0
533 Recognized Expert Contributor
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
alexseow
6 New Member
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 Recognized Expert Contributor
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 Recognized Expert Expert
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
alexseow
6 New Member
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 New Member
hi, i was wandering....ca n 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 New Member
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
12029
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
1311
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
2282
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 instead of the image. I'm using response.write. The Folder is called : images
10
7413
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 recommend storing the image to the filesystem and only keeping a pointer to that in the table. I want to dump the image to a table. My code dumps the data into the table, however, I get the following error when trying to view the image "the image ......
1
2338
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. THE Database used is MySQL "Support" on a Table Called "profiles": The problem is how do I get this piece of codes to link to a details page called "PATRONS_DETAILS.PHP" and display information about one particular database detail. With ID...
11
26650
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 and PEAR is in c:\wamp\php\pear I modified php.ini in the c:\wamp\php directory to reflect the actual path, but even stopping and restarting my server shows the c: \php5\pear path. I can't change it no matter what I do I also tried the...
4
6658
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, png1, png2 from png"; $result=mysql_query($dbQuery) or die("Could not get file list"); // to display
48
41440
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 database is the only one that displays.. i am using mysql as database here's the code.. tell me what's my error and pls. kindly edit it.. **imgdata = it is where i store the image.. longblob is the data type <?php $errmsg = "";
6
14429
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 and the image from the database also in one web page... how can i do this? pls help..... thanks.
0
9794
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9319
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5623
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5788
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4420
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3077
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.