Update: i Found my first mistake and changed the post to adress a different error in the same Code-Snippet, sorry :/

Hello fellow Monks!
I'm currently writing a small CGI-Script that, among other things, tries to feed images from a Mysql-DB to the browser. But for some strange reason i can't read both content-type and data from within the same SQL-Statement:

my $sql = "select type,data from bilder where id =?"; my $sth = $dbh->prepare($sql); $sth->execute( $q->param('id') ); my $error = 0; (my $type, my $data) = $sth->fetchrow() || ( $error = 1 ); binmode(STDOUT); if ( $error == 1 ) { print $q->header( -type => "image/gif" ); open( IN, "templates/keinbild.gif" ); binmode(IN); while (<IN>) { print; } close(IN); } else { print $q->header( -type => $type ); print $data; }
$type should be 'image/gif', 'image/png' or 'image/jpeg', depending on the output of Image::Info.

Adding a warn($type) gives:

[Sun Dec 18 11:24:34 2005] [error] [client 192.168.x.y] (\xa2\x80, ref +erer: http://server.lan/cgi-bin/index.pl?action=picman
DB is as follows:
CREATE TABLE `bilder` ( `id` int(11) NOT NULL auto_increment, `data` longblob NOT NULL, `type` enum('image/jpeg','image/gif','image/png') NOT NULL default ' +image/jpeg', `resx` int(11) NOT NULL default '0', `resy` int(11) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
Does anyone know what's wrong here?

Thank you in advance
Braindead_One


In reply to Mysql and Images by Braindead_One

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.