Re: cant view image from database
| From: | Tim Streater | Date: | Thu, 12 Feb 2015 22:41:00 +0000 |
| Subject: | Re: cant view image from database | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-324448@lists.php.net to get a copy of this message | ||
On 12 Feb 2015 at 21:58, hadi <almarzuki2011@hotmail.com> wrote:
> Hi Tul,
>
> I did exactly what you suggest me.
No you didn't.
> showimage1.php
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
> "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>dispaly image</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
> />
> </head>
>
> <body>
Remove all the above html from showimage1.php - all of it. showimage1.php should start with the
<?php line that follows here. You must NOT output anything before the header() below. The html
above is "output".
> <?php error_reporting(E_ALL); ini_set('display_errors', 1);
>
> $servername = "localhost";
> $username = "recorduser";
> $password = "password123";
> $database = "record";
>
> // Create connection
> $conn = mysqli_connect($servername, $username, $password, $database);
> // Check connection
> if (!$conn) {
> die("Connection failed: " . mysqli_connect_error());
> }
>
> $sql = "SELECT * FROM picture";
> $result = mysqli_query($conn, $sql);
>
> header("Content-type: image/jpeg");
> $row = mysqli_fetch_array($result);
> $img = $row["image"];
>
>
> echo $img;
And you don't need the html after here either.
--
Cheers -- Tim