in reply to Images
in thread Images

Hello...here are my $0.02...I would use a different method from sth (fetchrow()) and, assuming that you meant to use $sno in place of $phone, would change the code in your while loop thusly:

#!/usr/bin/perl use DBI; $user="mydb1"; $password="mydb1"; print "Content-type:text/html\n\n"; my $dbh = DBI->connect("dbi:mysql:mydb", $user, $password) or die "Can +'t connect to $data_source: $DBI::errstr"; print "successful connection\n"; my $sth = $dbh->prepare( q{SELECT sno, name FROM IMAGE}) or die "Can't + prepare statement: $DBI::errstr"; my $rc = $sth->execute or die "Can't execute statement: $DBI::errstr"; print "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n"; print "Field names: @{ $sth->{NAME} }\n";
while ( my($sno, $name) = $sth->fetchrow() ) { print "$name: $sno\n"; print "<img src=\"" . $name . "\" >\n"; } $sth->finish;
$dbh->disconnect; print "succefully disconnected\n"; print "</body></html>\n";

Replies are listed 'Best First'.
Re: Re: Images
by Anonymous Monk on Oct 25, 2002 at 10:32 UTC
    Hi, Thanks for your kind response. I've changed my code.but still ....can't get it. my new code is aas follows...
    #!/usr/bin/perl use strict; use DBI; my ($user,$password,$sno,$name,$datasource,$h); $user="mydb1"; $password="mydb1"; print "Content-type:text/html\n\n"; my $h = qq{<html><body>}; my $dbh = DBI->connect("dbi:mysql:mydb", $user, $password) or die "Can +'t connect to "; my $sth = $dbh->prepare( q{SELECT sno, name FROM IMAGE}) or die "Can't + prepare statement: $DBI::errstr"; my $rc = $sth->execute or die "Can't execute statement: $DBI::errstr +"; while ( my($sno, $name) = $sth->fetchrow() ) { $h .= qq{$name}; } $sth->finish; print $h; print "</body></html>\n"; $dbh->disconnect;
    The images are not appearing .

    Edit kudra, 2002-10-27 Code tags

      Hi - in that code as far as I can see you're not generating any <IMG> tags. You should really look at CGI.pm but in the meantime changing

      print $h;

      to
      print "<IMG src=\"".$h."\">;
      may help.

      Hey, if there's code up ^^ there ^^, don't blame me if it doesn't work.

      But today you took me walking, Through a land that we have lost,
      While our children sit at websites, With no access to the cost