473,378 Members | 1,609 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,378 software developers and data experts.

Display an image from database

Hello everyone,

I want to display an image on the webpage which was uploaded and stored in the database.

Here is my HTML codes
Expand|Select|Wrap|Line Numbers
  1. <img src="getImage.php?id={$student_id} <?php echo $data["LRCard"]?>;" width="175" height="200" />
  2.  
and here is my getImage.php codes

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   include 'Connect.php';
  3.   mysql_select_db("student");
  4.   $id = $_GET['id'];
  5.   $student_id = htmlentities($_REQUEST['id'], ENT_QUOTES);
  6.   $result = mysql_query("SELECT LRCard FROM student_information where student_id='$_GET[id]'");
  7.   $row = mysql_fetch_assoc($result);
  8.   $row = mysql_fetch_object($result);
  9.   mysql_close($link);  
  10.  
  11.   header("Content-type: image/jpeg");
  12.   header("Content-type: image/gif");
  13.   echo $row['LRCard'];
  14. ?>
  15.  
The image won't display :-(
Please anyone here can help me modify this codes.
May 19 '14 #1
9 1908
Dormilich
8,658 Expert Mod 8TB
The image won't display
of course not. your own code duplicates getting in your way. deleting lines #4, #5 & #8 should help as a quick’n’dirty fix.

nevertheless, you’re still susceptible to SQL Injection and you use the deprecated mysql functions.
May 20 '14 #2
Hi Dormilich,

I have followed your advise but it still doesn't display. The dimension is there but the picture is broken.


nevertheless, you’re still susceptible to SQL Injection and you use the deprecated mysql functions.


What do you mean by this? Please advise.
May 20 '14 #3
Dormilich
8,658 Expert Mod 8TB
nevertheless, you’re still susceptible to SQL Injection and you use the deprecated mysql functions.
What do you mean by this? Please advise.
see http://en.wikipedia.org/wiki/Sql_injection and http://php.net/mysql-query.
May 20 '14 #4
Dormilich
8,658 Expert Mod 8TB
load getImage.php?id=<enter-valid-id-here> in the address bar and check if there are any error messages.
May 20 '14 #5
Hi Dormilich,

It shows no error but a broken image on the upper right.
What does it signifies?
May 20 '14 #6
Thanks i will check that link im sure it will add to my learnings.
May 20 '14 #7
Dormilich
8,658 Expert Mod 8TB
What does it signifies?
the image data are incorrectly parsed.

possible reasons:
- wrong header (a gif image with a jpeg MIME header won’t display)
- additional text data before, inside or after the binary image data
- the binary image data itself are corrupted
May 20 '14 #8
so does it mean there is nothing wrong woth my codes or i need to add some headers or modified it?
May 28 '14 #9
Dormilich
8,658 Expert Mod 8TB
I don’t know your current code, I don‘t know what you have saved in your DB, I don’t know what headers you receive or what are necessary, I don’t know if there are any errors (reported).

If I have this information, I can give you an answer.
May 28 '14 #10

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

Similar topics

1
by: Tan | last post by:
Hi I am desperate for any help with display image in Gridview I have a gridview contain surname , forename ..... and image. I could not display image as my database store the column image as...
3
by: harish | last post by:
Hi friends I am facing problem as follow I can't display image from SQL Database to Picture box Control. Here are the codes that I am writing Dim arrPicture() As Byte = _
2
by: RedSouljaz | last post by:
Hi, How to display image that was saved in database ms sql server 2000 into picture box. The field type that I use in database is Images I can save to database but cannot show from database. ...
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
7
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed...
7
by: alexseow | last post by:
Query.asp <%@ LANGUAGE="VBSCRIPT" %> <!-- #include file="../../includes/dbconn.asp"--> <% dim MyRs, sqlstr, MyConn Response.Expires = 0 Response.Buffer = TRUE Response.Clear
1
by: shalini328 | last post by:
I am using ASP.net 1.1 C# and database is MS access.Can you tell me how can i display image from database
1
by: saadkhan | last post by:
I want to display image in <img> tag using database. I just need to know that how could i be able to define path or whatever to <img> tag. I have no probem in making queries to database.....plz help
5
by: SafaaDalloul | last post by:
Please I want know How I can Display Image from database randomly when the web page refresh in Asp.net by C# code
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.