How to retrieve images in BLOB format from MySQL database and display in an html tag?How do I quickly rename a MySQL database (change schema name)?Convert from MySQL datetime to another format with PHPHow do I retrieve an HTML element's actual width and height?How to output MySQL query results in CSV format?How do I connect to a MySQL Database in Python?How to display HTML in TextView?How to display Base64 images in HTML?How to retrieve the current version of a MySQL database?How to get the sizes of the tables of a MySQL database?PHP - images stored as BLOB displayed as broken links
Writing "hahaha" versus describing the laugh
What is Orcus doing with Mind Flayers in the art on the last page of Volo's Guide to Monsters?
How to remove new line added by readarray when using a delimiter?
What is to the west of Westeros?
What is the limit to a Glyph of Warding's trigger?
How would a developer who mostly fixed bugs for years at a company call out their contributions in their CV?
Did significant numbers of Japanese officers escape prosecution during the Tokyo Trials?
The disk image is 497GB smaller than the target device
Was this scene in S8E06 added because of fan reactions to S8E04?
One word for 'the thing that attracts me'?
Why did other houses not demand this?
Is superuser the same as root?
Physical only checkdb is failing, but full one is completed successfully
Is there a simple example that empirical evidence is misleading?
Visual Block Mode edit with sequential number
What could be my risk mitigation strategies if my client wants to contract UAT?
Are there any German nonsense poems (Jabberwocky)?
Cisco 3750X Power Cable
Complications of displaced core material?
How do you earn the reader's trust?
Where is Jon going?
Possibility of faking someone's public key
How to escape dependency hell?
Alexandrov's generalization of Cauchy's rigidity theorem
How to retrieve images in BLOB format from MySQL database and display in an html tag?
How do I quickly rename a MySQL database (change schema name)?Convert from MySQL datetime to another format with PHPHow do I retrieve an HTML element's actual width and height?How to output MySQL query results in CSV format?How do I connect to a MySQL Database in Python?How to display HTML in TextView?How to display Base64 images in HTML?How to retrieve the current version of a MySQL database?How to get the sizes of the tables of a MySQL database?PHP - images stored as BLOB displayed as broken links
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I created a MySQL database with a table using phpmyadmin. I created this table with a BLOB column to hold a .jpg file.
At the moment i'm trying to display the image (BLOB) in an HTML tag to no success. I'm only getting the broken image icon when running the code.
Note: I know it's not recommended to do this, but currently i have too.
I've already tried looking up various questions here in stackoverflow.com, quora.com, and codeofaninja.com, and tried implementing various solutions that seemed to have worked for other people, but they haven't worked for me.
Where i'm displaying the information (test.php):
<html>
<img src="getImage.php?id=10" width="175" height="200" />
</html>
Code i'm trying to use to display image (getImage.php)
<?php
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db("unirentas");
$id = $_GET['id'];
// do some validation here to ensure id is safe
$sql = "SELECT imagen FROM propiedades WHERE ID_renta=$id";
$result = mysqli_query("$sql");
$row = mysqli_fetch_assoc($result);
mysqli_close($link);
header("Content-type: image/jpg");
echo $row['imagen'];
?>
This should be displaying all the rows that are within the database along with the same image, but what it does is display all the rows with their corresponding information and the broken image.
php html mysql image blob
add a comment |
I created a MySQL database with a table using phpmyadmin. I created this table with a BLOB column to hold a .jpg file.
At the moment i'm trying to display the image (BLOB) in an HTML tag to no success. I'm only getting the broken image icon when running the code.
Note: I know it's not recommended to do this, but currently i have too.
I've already tried looking up various questions here in stackoverflow.com, quora.com, and codeofaninja.com, and tried implementing various solutions that seemed to have worked for other people, but they haven't worked for me.
Where i'm displaying the information (test.php):
<html>
<img src="getImage.php?id=10" width="175" height="200" />
</html>
Code i'm trying to use to display image (getImage.php)
<?php
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db("unirentas");
$id = $_GET['id'];
// do some validation here to ensure id is safe
$sql = "SELECT imagen FROM propiedades WHERE ID_renta=$id";
$result = mysqli_query("$sql");
$row = mysqli_fetch_assoc($result);
mysqli_close($link);
header("Content-type: image/jpg");
echo $row['imagen'];
?>
This should be displaying all the rows that are within the database along with the same image, but what it does is display all the rows with their corresponding information and the broken image.
php html mysql image blob
If you opengetImage.php
in a new browser window, you should see errors. That's because your calls tomysqli_select_db()
andmysqli_query()
are missing the$link
argument. Why aren't you using the object-oriented api (i.e.$link->select_db()
and$link->query()
) like you are intest.php
?
– rickdenhaan
Mar 23 at 22:05
Note: I know it's not recommended to do this, but currently i have too.
Why? is there a specific reason you need this way? Perhaps this is an X-Y problem we can help you with?
– Chipster
Mar 23 at 22:09
Thank you for responding. The thing is i'm currently working on a school project , i'm pretty much a beginer in this and i'm using a java project to insert data into the MysQL database, the only way i found to do it was using the BLOB type.
– Vyrus C.Krysis
Mar 23 at 22:44
And in regards to your first question, both code blocks are derived from other solutions i tried from stackoverflow questions. Like i said i'm really just at a beginner level and i'm not sure how everything works.
– Vyrus C.Krysis
Mar 23 at 22:51
add a comment |
I created a MySQL database with a table using phpmyadmin. I created this table with a BLOB column to hold a .jpg file.
At the moment i'm trying to display the image (BLOB) in an HTML tag to no success. I'm only getting the broken image icon when running the code.
Note: I know it's not recommended to do this, but currently i have too.
I've already tried looking up various questions here in stackoverflow.com, quora.com, and codeofaninja.com, and tried implementing various solutions that seemed to have worked for other people, but they haven't worked for me.
Where i'm displaying the information (test.php):
<html>
<img src="getImage.php?id=10" width="175" height="200" />
</html>
Code i'm trying to use to display image (getImage.php)
<?php
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db("unirentas");
$id = $_GET['id'];
// do some validation here to ensure id is safe
$sql = "SELECT imagen FROM propiedades WHERE ID_renta=$id";
$result = mysqli_query("$sql");
$row = mysqli_fetch_assoc($result);
mysqli_close($link);
header("Content-type: image/jpg");
echo $row['imagen'];
?>
This should be displaying all the rows that are within the database along with the same image, but what it does is display all the rows with their corresponding information and the broken image.
php html mysql image blob
I created a MySQL database with a table using phpmyadmin. I created this table with a BLOB column to hold a .jpg file.
At the moment i'm trying to display the image (BLOB) in an HTML tag to no success. I'm only getting the broken image icon when running the code.
Note: I know it's not recommended to do this, but currently i have too.
I've already tried looking up various questions here in stackoverflow.com, quora.com, and codeofaninja.com, and tried implementing various solutions that seemed to have worked for other people, but they haven't worked for me.
Where i'm displaying the information (test.php):
<html>
<img src="getImage.php?id=10" width="175" height="200" />
</html>
Code i'm trying to use to display image (getImage.php)
<?php
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db("unirentas");
$id = $_GET['id'];
// do some validation here to ensure id is safe
$sql = "SELECT imagen FROM propiedades WHERE ID_renta=$id";
$result = mysqli_query("$sql");
$row = mysqli_fetch_assoc($result);
mysqli_close($link);
header("Content-type: image/jpg");
echo $row['imagen'];
?>
This should be displaying all the rows that are within the database along with the same image, but what it does is display all the rows with their corresponding information and the broken image.
php html mysql image blob
php html mysql image blob
edited Mar 23 at 22:47
Vyrus C.Krysis
asked Mar 23 at 22:00
Vyrus C.KrysisVyrus C.Krysis
12
12
If you opengetImage.php
in a new browser window, you should see errors. That's because your calls tomysqli_select_db()
andmysqli_query()
are missing the$link
argument. Why aren't you using the object-oriented api (i.e.$link->select_db()
and$link->query()
) like you are intest.php
?
– rickdenhaan
Mar 23 at 22:05
Note: I know it's not recommended to do this, but currently i have too.
Why? is there a specific reason you need this way? Perhaps this is an X-Y problem we can help you with?
– Chipster
Mar 23 at 22:09
Thank you for responding. The thing is i'm currently working on a school project , i'm pretty much a beginer in this and i'm using a java project to insert data into the MysQL database, the only way i found to do it was using the BLOB type.
– Vyrus C.Krysis
Mar 23 at 22:44
And in regards to your first question, both code blocks are derived from other solutions i tried from stackoverflow questions. Like i said i'm really just at a beginner level and i'm not sure how everything works.
– Vyrus C.Krysis
Mar 23 at 22:51
add a comment |
If you opengetImage.php
in a new browser window, you should see errors. That's because your calls tomysqli_select_db()
andmysqli_query()
are missing the$link
argument. Why aren't you using the object-oriented api (i.e.$link->select_db()
and$link->query()
) like you are intest.php
?
– rickdenhaan
Mar 23 at 22:05
Note: I know it's not recommended to do this, but currently i have too.
Why? is there a specific reason you need this way? Perhaps this is an X-Y problem we can help you with?
– Chipster
Mar 23 at 22:09
Thank you for responding. The thing is i'm currently working on a school project , i'm pretty much a beginer in this and i'm using a java project to insert data into the MysQL database, the only way i found to do it was using the BLOB type.
– Vyrus C.Krysis
Mar 23 at 22:44
And in regards to your first question, both code blocks are derived from other solutions i tried from stackoverflow questions. Like i said i'm really just at a beginner level and i'm not sure how everything works.
– Vyrus C.Krysis
Mar 23 at 22:51
If you open
getImage.php
in a new browser window, you should see errors. That's because your calls to mysqli_select_db()
and mysqli_query()
are missing the $link
argument. Why aren't you using the object-oriented api (i.e. $link->select_db()
and $link->query()
) like you are in test.php
?– rickdenhaan
Mar 23 at 22:05
If you open
getImage.php
in a new browser window, you should see errors. That's because your calls to mysqli_select_db()
and mysqli_query()
are missing the $link
argument. Why aren't you using the object-oriented api (i.e. $link->select_db()
and $link->query()
) like you are in test.php
?– rickdenhaan
Mar 23 at 22:05
Note: I know it's not recommended to do this, but currently i have too.
Why? is there a specific reason you need this way? Perhaps this is an X-Y problem we can help you with?– Chipster
Mar 23 at 22:09
Note: I know it's not recommended to do this, but currently i have too.
Why? is there a specific reason you need this way? Perhaps this is an X-Y problem we can help you with?– Chipster
Mar 23 at 22:09
Thank you for responding. The thing is i'm currently working on a school project , i'm pretty much a beginer in this and i'm using a java project to insert data into the MysQL database, the only way i found to do it was using the BLOB type.
– Vyrus C.Krysis
Mar 23 at 22:44
Thank you for responding. The thing is i'm currently working on a school project , i'm pretty much a beginer in this and i'm using a java project to insert data into the MysQL database, the only way i found to do it was using the BLOB type.
– Vyrus C.Krysis
Mar 23 at 22:44
And in regards to your first question, both code blocks are derived from other solutions i tried from stackoverflow questions. Like i said i'm really just at a beginner level and i'm not sure how everything works.
– Vyrus C.Krysis
Mar 23 at 22:51
And in regards to your first question, both code blocks are derived from other solutions i tried from stackoverflow questions. Like i said i'm really just at a beginner level and i'm not sure how everything works.
– Vyrus C.Krysis
Mar 23 at 22:51
add a comment |
2 Answers
2
active
oldest
votes
Your first error is that you have written a program which does lots of things and are then trying to work out why none of them are working. You should have created a Minimal, Verifiable and Complete script to test this and fix that first - the entirety of the first script you posted here should be replaced with:
<html>
<img src="getImage.php?id=10" />
</html>
You should also have posted the code which writes the data to the database.Neither you nor we know if the problem is with the data written to the database or is occurring when you retrieve the data.
You should also be checking that you're error logging/reporting is working correctly and that PHP is not already telling you what the error is.
Other things you can try are writing the data to a file and checking if it you really do have a image file, looking at the headers returned by getimage.php to make sure they are what you expect.
Finally, do take some time to learn a little about secure programming before you pug code like this into the internet - there are a lot of security problems here.
Thank you for responding. I'll take what you said into consideration and edit my post to make it clearer.
– Vyrus C.Krysis
Mar 23 at 22:44
add a comment |
I found the solution to my problem, i used the base64_encode($blob); function
<?php
// Server credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "unirentas";
// Creating mysql connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Checking mysql connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);
// Writing a mysql query to retrieve data
$sql = "SELECT ID_renta, calle, smz, mz, lote, precio, universidad, fecha, imagen, nombre, telefono, correo FROM propiedades";
$result = $conn->query($sql);
if ($result->num_rows > 0)
// Show each data returned by mysql
while($row = $result->fetch_assoc())
$ID_renta = $row["ID_renta"];
$calle = $row["calle"];
$smz = $row["smz"];
$mz = $row["mz"];
$lote = $row["lote"];
$precio = $row["precio"];
$universidad = $row["universidad"];
$fecha = $row["fecha"];
$blob = $row["imagen"];
$nombre = $row["nombre"];
$telefono = $row["telefono"];
$correo = $row["correo"];
echo "
<!-- USING HTML HERE : -->
<p> ID : $ID_renta</p>
<p> Calle : $calle </p>
<p> Smz : $smz </p>
<p> Mz : $mz </p>
<p> Lote : $lote </p>
<p> Precio : $precio </p>
<p> Universidad : $universidad </p>";
echo '<img src="data:image/png;base64,'.base64_encode($blob).'"/>';
echo "<p> Fecha_ $fecha </p>
<p> Nombre : $nombre </p>
<p> Telefono : $telefono </p>
<p> Correo : $correo </p>
<p>////////////////////////////////////////////////////////////////////////////////</p>
";
else
echo "0 results";
// Closing mysql connection
$conn->close();
?>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318795%2fhow-to-retrieve-images-in-blob-format-from-mysql-database-and-display-in-an-html%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your first error is that you have written a program which does lots of things and are then trying to work out why none of them are working. You should have created a Minimal, Verifiable and Complete script to test this and fix that first - the entirety of the first script you posted here should be replaced with:
<html>
<img src="getImage.php?id=10" />
</html>
You should also have posted the code which writes the data to the database.Neither you nor we know if the problem is with the data written to the database or is occurring when you retrieve the data.
You should also be checking that you're error logging/reporting is working correctly and that PHP is not already telling you what the error is.
Other things you can try are writing the data to a file and checking if it you really do have a image file, looking at the headers returned by getimage.php to make sure they are what you expect.
Finally, do take some time to learn a little about secure programming before you pug code like this into the internet - there are a lot of security problems here.
Thank you for responding. I'll take what you said into consideration and edit my post to make it clearer.
– Vyrus C.Krysis
Mar 23 at 22:44
add a comment |
Your first error is that you have written a program which does lots of things and are then trying to work out why none of them are working. You should have created a Minimal, Verifiable and Complete script to test this and fix that first - the entirety of the first script you posted here should be replaced with:
<html>
<img src="getImage.php?id=10" />
</html>
You should also have posted the code which writes the data to the database.Neither you nor we know if the problem is with the data written to the database or is occurring when you retrieve the data.
You should also be checking that you're error logging/reporting is working correctly and that PHP is not already telling you what the error is.
Other things you can try are writing the data to a file and checking if it you really do have a image file, looking at the headers returned by getimage.php to make sure they are what you expect.
Finally, do take some time to learn a little about secure programming before you pug code like this into the internet - there are a lot of security problems here.
Thank you for responding. I'll take what you said into consideration and edit my post to make it clearer.
– Vyrus C.Krysis
Mar 23 at 22:44
add a comment |
Your first error is that you have written a program which does lots of things and are then trying to work out why none of them are working. You should have created a Minimal, Verifiable and Complete script to test this and fix that first - the entirety of the first script you posted here should be replaced with:
<html>
<img src="getImage.php?id=10" />
</html>
You should also have posted the code which writes the data to the database.Neither you nor we know if the problem is with the data written to the database or is occurring when you retrieve the data.
You should also be checking that you're error logging/reporting is working correctly and that PHP is not already telling you what the error is.
Other things you can try are writing the data to a file and checking if it you really do have a image file, looking at the headers returned by getimage.php to make sure they are what you expect.
Finally, do take some time to learn a little about secure programming before you pug code like this into the internet - there are a lot of security problems here.
Your first error is that you have written a program which does lots of things and are then trying to work out why none of them are working. You should have created a Minimal, Verifiable and Complete script to test this and fix that first - the entirety of the first script you posted here should be replaced with:
<html>
<img src="getImage.php?id=10" />
</html>
You should also have posted the code which writes the data to the database.Neither you nor we know if the problem is with the data written to the database or is occurring when you retrieve the data.
You should also be checking that you're error logging/reporting is working correctly and that PHP is not already telling you what the error is.
Other things you can try are writing the data to a file and checking if it you really do have a image file, looking at the headers returned by getimage.php to make sure they are what you expect.
Finally, do take some time to learn a little about secure programming before you pug code like this into the internet - there are a lot of security problems here.
answered Mar 23 at 22:15
symcbeansymcbean
41.7k54277
41.7k54277
Thank you for responding. I'll take what you said into consideration and edit my post to make it clearer.
– Vyrus C.Krysis
Mar 23 at 22:44
add a comment |
Thank you for responding. I'll take what you said into consideration and edit my post to make it clearer.
– Vyrus C.Krysis
Mar 23 at 22:44
Thank you for responding. I'll take what you said into consideration and edit my post to make it clearer.
– Vyrus C.Krysis
Mar 23 at 22:44
Thank you for responding. I'll take what you said into consideration and edit my post to make it clearer.
– Vyrus C.Krysis
Mar 23 at 22:44
add a comment |
I found the solution to my problem, i used the base64_encode($blob); function
<?php
// Server credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "unirentas";
// Creating mysql connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Checking mysql connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);
// Writing a mysql query to retrieve data
$sql = "SELECT ID_renta, calle, smz, mz, lote, precio, universidad, fecha, imagen, nombre, telefono, correo FROM propiedades";
$result = $conn->query($sql);
if ($result->num_rows > 0)
// Show each data returned by mysql
while($row = $result->fetch_assoc())
$ID_renta = $row["ID_renta"];
$calle = $row["calle"];
$smz = $row["smz"];
$mz = $row["mz"];
$lote = $row["lote"];
$precio = $row["precio"];
$universidad = $row["universidad"];
$fecha = $row["fecha"];
$blob = $row["imagen"];
$nombre = $row["nombre"];
$telefono = $row["telefono"];
$correo = $row["correo"];
echo "
<!-- USING HTML HERE : -->
<p> ID : $ID_renta</p>
<p> Calle : $calle </p>
<p> Smz : $smz </p>
<p> Mz : $mz </p>
<p> Lote : $lote </p>
<p> Precio : $precio </p>
<p> Universidad : $universidad </p>";
echo '<img src="data:image/png;base64,'.base64_encode($blob).'"/>';
echo "<p> Fecha_ $fecha </p>
<p> Nombre : $nombre </p>
<p> Telefono : $telefono </p>
<p> Correo : $correo </p>
<p>////////////////////////////////////////////////////////////////////////////////</p>
";
else
echo "0 results";
// Closing mysql connection
$conn->close();
?>
add a comment |
I found the solution to my problem, i used the base64_encode($blob); function
<?php
// Server credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "unirentas";
// Creating mysql connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Checking mysql connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);
// Writing a mysql query to retrieve data
$sql = "SELECT ID_renta, calle, smz, mz, lote, precio, universidad, fecha, imagen, nombre, telefono, correo FROM propiedades";
$result = $conn->query($sql);
if ($result->num_rows > 0)
// Show each data returned by mysql
while($row = $result->fetch_assoc())
$ID_renta = $row["ID_renta"];
$calle = $row["calle"];
$smz = $row["smz"];
$mz = $row["mz"];
$lote = $row["lote"];
$precio = $row["precio"];
$universidad = $row["universidad"];
$fecha = $row["fecha"];
$blob = $row["imagen"];
$nombre = $row["nombre"];
$telefono = $row["telefono"];
$correo = $row["correo"];
echo "
<!-- USING HTML HERE : -->
<p> ID : $ID_renta</p>
<p> Calle : $calle </p>
<p> Smz : $smz </p>
<p> Mz : $mz </p>
<p> Lote : $lote </p>
<p> Precio : $precio </p>
<p> Universidad : $universidad </p>";
echo '<img src="data:image/png;base64,'.base64_encode($blob).'"/>';
echo "<p> Fecha_ $fecha </p>
<p> Nombre : $nombre </p>
<p> Telefono : $telefono </p>
<p> Correo : $correo </p>
<p>////////////////////////////////////////////////////////////////////////////////</p>
";
else
echo "0 results";
// Closing mysql connection
$conn->close();
?>
add a comment |
I found the solution to my problem, i used the base64_encode($blob); function
<?php
// Server credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "unirentas";
// Creating mysql connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Checking mysql connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);
// Writing a mysql query to retrieve data
$sql = "SELECT ID_renta, calle, smz, mz, lote, precio, universidad, fecha, imagen, nombre, telefono, correo FROM propiedades";
$result = $conn->query($sql);
if ($result->num_rows > 0)
// Show each data returned by mysql
while($row = $result->fetch_assoc())
$ID_renta = $row["ID_renta"];
$calle = $row["calle"];
$smz = $row["smz"];
$mz = $row["mz"];
$lote = $row["lote"];
$precio = $row["precio"];
$universidad = $row["universidad"];
$fecha = $row["fecha"];
$blob = $row["imagen"];
$nombre = $row["nombre"];
$telefono = $row["telefono"];
$correo = $row["correo"];
echo "
<!-- USING HTML HERE : -->
<p> ID : $ID_renta</p>
<p> Calle : $calle </p>
<p> Smz : $smz </p>
<p> Mz : $mz </p>
<p> Lote : $lote </p>
<p> Precio : $precio </p>
<p> Universidad : $universidad </p>";
echo '<img src="data:image/png;base64,'.base64_encode($blob).'"/>';
echo "<p> Fecha_ $fecha </p>
<p> Nombre : $nombre </p>
<p> Telefono : $telefono </p>
<p> Correo : $correo </p>
<p>////////////////////////////////////////////////////////////////////////////////</p>
";
else
echo "0 results";
// Closing mysql connection
$conn->close();
?>
I found the solution to my problem, i used the base64_encode($blob); function
<?php
// Server credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "unirentas";
// Creating mysql connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Checking mysql connection
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);
// Writing a mysql query to retrieve data
$sql = "SELECT ID_renta, calle, smz, mz, lote, precio, universidad, fecha, imagen, nombre, telefono, correo FROM propiedades";
$result = $conn->query($sql);
if ($result->num_rows > 0)
// Show each data returned by mysql
while($row = $result->fetch_assoc())
$ID_renta = $row["ID_renta"];
$calle = $row["calle"];
$smz = $row["smz"];
$mz = $row["mz"];
$lote = $row["lote"];
$precio = $row["precio"];
$universidad = $row["universidad"];
$fecha = $row["fecha"];
$blob = $row["imagen"];
$nombre = $row["nombre"];
$telefono = $row["telefono"];
$correo = $row["correo"];
echo "
<!-- USING HTML HERE : -->
<p> ID : $ID_renta</p>
<p> Calle : $calle </p>
<p> Smz : $smz </p>
<p> Mz : $mz </p>
<p> Lote : $lote </p>
<p> Precio : $precio </p>
<p> Universidad : $universidad </p>";
echo '<img src="data:image/png;base64,'.base64_encode($blob).'"/>';
echo "<p> Fecha_ $fecha </p>
<p> Nombre : $nombre </p>
<p> Telefono : $telefono </p>
<p> Correo : $correo </p>
<p>////////////////////////////////////////////////////////////////////////////////</p>
";
else
echo "0 results";
// Closing mysql connection
$conn->close();
?>
answered Mar 24 at 3:14
Vyrus C.KrysisVyrus C.Krysis
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318795%2fhow-to-retrieve-images-in-blob-format-from-mysql-database-and-display-in-an-html%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you open
getImage.php
in a new browser window, you should see errors. That's because your calls tomysqli_select_db()
andmysqli_query()
are missing the$link
argument. Why aren't you using the object-oriented api (i.e.$link->select_db()
and$link->query()
) like you are intest.php
?– rickdenhaan
Mar 23 at 22:05
Note: I know it's not recommended to do this, but currently i have too.
Why? is there a specific reason you need this way? Perhaps this is an X-Y problem we can help you with?– Chipster
Mar 23 at 22:09
Thank you for responding. The thing is i'm currently working on a school project , i'm pretty much a beginer in this and i'm using a java project to insert data into the MysQL database, the only way i found to do it was using the BLOB type.
– Vyrus C.Krysis
Mar 23 at 22:44
And in regards to your first question, both code blocks are derived from other solutions i tried from stackoverflow questions. Like i said i'm really just at a beginner level and i'm not sure how everything works.
– Vyrus C.Krysis
Mar 23 at 22:51