Can't really see anything that would cause problems... I would pepper the code with debug statements and look at the log files to see where things are dying.
I have couple of comments on the code itself though. You really should remove the use CGI::Carp('fatalsToBrowser'); since this script returns an image and fatalsToBrowser generates HTML. And more importantly, you should be using placeholders in your SQL statement. You take a value provided by the browser and plug it straight into your SQL statement without checking anything. Changing it to something like the following will make things much safer:
my %IMG_FIELDS = {
field1 => 'Field1',
field2 => 'Field2',
};
die "Invalid img parameter $img" unless $IMG_FIELDS{$img};
my $sql = "SELECT $IMG_FIELDS{$img} FROM listings WHERE pc_mls_id = ?"
+;
my $sth = $dbh->prepare($sql)
or die "Couldn't prepare: $DBI::errstr\n";
$sth->execute($mls_id);
You can't use a placeholder to select a column dynamically (at least my quick test in PostgreSQL didn't allow it), so we use a lookup table for that one. For the pc_mls_id we use a placeholder. The value automatically gets quoted by DBI to protect it from any nasties that your users may put in there.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|