Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2000071

[PHP] "get" variables, before or after header sent? From: Benton Jackson (goatrider <email protected>)
Date: 07/12/00

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!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>