Re: Re: session variable in select query showing picture from database

From: Date: Thu, 12 Feb 2009 19:24:49 +0000
Subject: Re: Re: session variable in select query showing picture from database
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-45945@lists.php.net to get a copy of this message
Don't see session_start() in your script. If you work with SESSION, you must have it on the first lines of the file (before any output and work with $_SESSION so it's good to put it on the first lines). And it must be in every file which works with them (except for included files). It should look like this: <?php
session_start(); // open session 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(); ?>
Mika Jaaksi napsal(a):
Still fighting with it... So, these work: $query="SELECT * FROM pic_upload; $query="SELECT * FROM pic_upload WHERE band_id=11"; picture is shown on the other page but when adding variable into query it doesn't show the picture on the other page $query="SELECT * FROM pic_upload WHERE band_id='{$band_id}'"; I'm out of ideas at the moment... ps. forget what I said about the weird markings... 2009/2/12 Mika Jaaksi <mika.jaaksi@gmail.com>
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...
    
-- S pozdravem Daniel Tlach Freelance webdeveloper Email: mail@danaketh.com ICQ: 160914875 MSN: danaketh@hotmail.com Jabber: danaketh@jabbim.cz

« previous php.db (#45945) next »