in reply to Images

Have you some code that is giving you problems - if so, post here and we'll see what we can do. Otherwise if you can give us some information on why you can't insert the images into the HTML - and of course you'll get the recommendation to look at CGI.PM.

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

Replies are listed 'Best First'.
Images
by Anonymous Monk on Oct 24, 2002 at 10:29 UTC
    Hi ,This is the code. Please help me and correct the script . thanks,Subhash email:kbs_subhash@yahoo.com
    #!/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 (($sno, $name) = $sth->fetchrow_array) { print "<h6>$name: $phone</h6>\n"; $line="<img src=".$name; $line=$line." >"; print "<img src=\"$line\">"; } $dbh->disconnect; print "succefully disconnected\n"; print "</body></html>\n";

    edited: Thu Oct 24 14:51:47 2002 by jeffa - code tags

      OK - if you can put your code in <CODE> tags, it's a bit easier to read, like this:

      #!/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 (($sno, $name) = $sth->fetchrow_array) { print "$name: $phone\n"; $line="<img src=".$name; $line=$line." >"; print "<img src=\"$line\">"; } $dbh->disconnect; print "succefully disconnected\n"; print "</body></html>\n";

      OK, so looking at the code, here's my thoughts:

      1. first of all, I'm going to repeat this - get used to CGI.pm, it'll make your life a lot easier.
      2. use strict - will catch a lot of errors, such as no definition of $phone
      3. You've got no <body> tag.
      4. There's no <P> tags surrounding your text
      5. You're generating HTML that looks something like <img src="<img src="filename">"> in the while loop

      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

      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";
        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

      The other monks definetely provided you with another way to do it. I'll just point out what seems to me to be wrong : I think that this part is the problem.
      $line="<img src=".$name; $line=$line." >"; print "<img src=\"$line\">";
      Wouldn't you want that last line to be just print $line; ?