Re: DBI CGI help
From: Jupiterhost.Net (mlists_at_jupiterhost.net)
Date: 05/17/04
- Next message: Tim Bunce: "(Fwd)"
- Previous message: Leegold: "Re: DBI CGI help"
- In reply to: Leegold: "Re: DBI CGI help"
- Next in thread: Leegold: "flat-file insert question"
- Reply: Leegold: "flat-file insert question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 16 May 2004 20:04:04 -0500 To: leegold <leegold@fastmail.fm>
leegold wrote:
> I have been looking for *clear, simple, upto date,
> working code examples* of using DBI and CGI.
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use CGI qw(header param);
> Requesting some action to be taken on a form
> from user and then returning the user's db select
> to them via the browser.
# WARNING : untested code ahead :) #
my $foo = param('foo');
print header();
if($foo) {
my $c = 0;
my $dbh = connect('your connect info here') or die DBI::errstr;
my $fooQ = $dbh->quote($foo);
my $records = $dbh->selectall_arrayref("SELECT Id, Bar FROM Stuff WHERE
Foo = $fooQ");
print "Your Foo will be <ul>\n";
for(@{ $records }) {
$c++;
my($id, $bar) = @_;
print "<li>$id $bar<li />\n";
}
print "</ul><br />I found $c Foo(s)<br />\n";
$dbh->disconnect();
}
print <<FORM;
<form action="this.pl" method="post">
Enter Your Foo <input type="text" name="foo" value="$foo" />
<input type="submit" value="Find Foo" />
</form>
FORM
> I been trying all day on the web and I have
> alot of fragmented stuff but nothing definative.
>
> Does anyone know of anything? I'd prefer something
> simple and recent. Thanks.
>
I know there are plenty of things I could improve in the code above but
that should get you started :)
perldoc DBI
perldoc CGI
HTH
Lee.M - JupiterHost.Net
- Next message: Tim Bunce: "(Fwd)"
- Previous message: Leegold: "Re: DBI CGI help"
- In reply to: Leegold: "Re: DBI CGI help"
- Next in thread: Leegold: "flat-file insert question"
- Reply: Leegold: "flat-file insert question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|