"get" variables, before or after header sent?

From: Date: Wed, 12 Jul 2000 15:42:52 +0000
Subject: "get" variables, before or after header sent?
Groups: php.general 
Request: Send a blank email to php-general+get-6160@lists.php.net to get a copy of this message
Near as I can tell, your "get" variables do not get set until after the header has been finished. Here's my observation: I'm trying to write a little script that retrieves an image out of a database, with the ID specified on the URL: <? $db=mysql_connect("localhost","dummy"); mysql_select_db("test"); $table=mysql_query("SELECT * FROM images WHERE id='$id'",$db); if ($table && $row=mysql_fetch_array($table)) { Header("Content-type: image/gif"); echo $row['image']; } else { echo "Image '$id' not found.<br>\n"; } ?> It returns "Image '' not found." when called with "id=1" on the URL. But if I stick a blank line before the "<?", forcing the header to be sent, it reads up the image and displays the image as text, of course complaining about being unable to send the header. If I put a "1" in place of "$id" in the query, then it retrieves something. (it's still not displaying anything, but it at least seems to try). Obviously, $id is not being set unless the header has already been sent! _______________________________________________ __ __ ___ _ |_) |_ |\ | | / \ |\ | Benton Jackson |_) |_ | \| | \_/ | \| benton@goatrider.com http://www.goatrider.com Maplewood, MN, USA

« previous php.general (#6160) next »