Re: session variable in select query showing picture from database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mika Jaaksi wrote:

> I'm trying to show picture from database. Everything works until I add
> variable into where part of the query.
> 
> It works with plain number. example ...WHERE id=11... ...picture is shown
> on the page.
> 
> Here's the code that retrieves the picture. show_pic.php
> 
> <?php
> function db_connect($host='********', $user='********',
> $password='********', $db='********')
> {
> mysql_connect($host, $user, $password) or die('I cannot connect to db: ' .
> mysql_error());
> mysql_select_db($db);
> }
> db_connect();
> $band_id = $_SESSION['session_var'];
> $query="SELECT * FROM pic_upload WHERE band_id=$band_id";
> $result=mysql_query($query);
> while($row = mysql_fetch_array($result))
> {
> $bytes = $row['pic_content'];
> }
> header("Content-type: image/jpeg");
> print $bytes;
> 
> 
> exit ();
> mysql_close();
> ?>
> 
> 
> other page that shows the picture
> 
> <?php
> echo "<img width='400px' src='./show_pic.php' />";
> ?>
> 
> Any help would be appreciated...

Where does $band_id come from? If from a form, and you have register_globals
set to (sensibly) OFF then you will need to use the $_POST or $_GET array,
depending on the METHOD of the form (POST or GET) to retrieve the value of
$band_id

Echoing $query will give you some useful information.



Cheers
-- 
David Robley

"I hate Chablis," Tom whined.
Today is Pungenday, the 43rd day of Chaos in the YOLD 3175. 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux