Hello, i have a problem with displaying a picture. Picture is stored in database as mediumblob. Storing pictures in database is going ok, since i can see them in phpmyadmin. Problem is, i can't see them in browser. THe code im using for this is here:

login.php

--lots of code before this one (mostly validation of forms) --
$_SESSION['avatar'] = "<img src=showImage.php?id=$userName />";
     -- I am saving the image to $_SESSION file to use it on another script.

Script that goes into database and print out the picture
showImage.php

<?php
include 'spajanje.php';   //file that has funvtions for connecting to database

spojiSeNaBazu();         //function to connect to database
if(isset($_GET['id']))       //check the url (passing the username (id))
{
    $id = (int)$_GET['id'];

    $upit = "SELECT * FROM korisnik WHERE username = $id";     //query
    $image = mysql_query($upit) or die (mysql_error());        //
    $red = mysql_fetch_array($image);                          //
    $avatar = $red['avatar'];                                 //
    header("Content-type: image/gif");
    echo $avatar;
}
else {

        echo "pogreska kod slanja url-a";                   //error

}

?>

and lastly, i have a script that shows image on browser via smarty templating:

_login.php (bold thing is important, at least i think so).

<?php

    session_start();
    require 'D:\wamp\Smarty-3.1.7\libs\Smarty.class.php';
    $smarty = new Smarty();
    if (isset($_GET['err']) && $_GET['err'] == 401)
        {
         $smarty->assign("nonAuthAccess", "Kako bi nastavili morate se prijaviti!");
        }
    if (isset($_COOKIE['user']));
    {
            $smarty->assign("cookiedUser", $_COOKIE['user']);
    }
    if (isset($_SESSION['sesija']) && isset($_SESSION['korisnik']))
    {

       ** $smarty->assign("slika", $_SESSION['avatar'] );**    // assigning to smarty
        $smarty->assign("uspjeh", $_SESSION['sesija']);
        $smarty->assign("userName", $_SESSION['korisnik']);
        $smarty->display('loginForm.tpl');
    }
    else {
            $smarty->display('loginForm.tpl');
    }
?>

the problem is that i get something like this image:

http://imageshack.us/f/38/capturewvm.png/

So, if anyone has an idea what might be the problem, I would so much appreciate it. Thank you.

nevermind, i got it...the problem was in query...i had to change

$id = (int)$_GET['id'];    
$upit = "SELECT * FROM korisnik WHERE username = $id";     //query

to

 $id = $_GET['id'];
 $upit = "SELECT * FROM korisnik WHERE username = '$id'";     //query
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.