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
| [reply] [d/l] |
#!/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:
- first of all, I'm going to repeat this - get used to CGI.pm, it'll make your life a lot easier.
- use strict - will catch a lot of errors, such as no definition of $phone
- You've got no <body> tag.
- There's no <P> tags surrounding your text
- 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
| [reply] [d/l] |
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";
| [reply] [d/l] [select] |
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
| [reply] [d/l] |
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; ?
| [reply] [d/l] |