#!/usr/bin/perl -Tw use strict; use CGI qw(:standard); use DBI; # connect to the database my $dbh = DBI->connect( qw(DBI:mysql:database:host user pass), ) or die $DBI::errstr; # prepare the SQL statement my $sth = $dbh->prepare(' select foo from baz where bar = ? ') or die "prepare failed"; # feed the SQL statement the criteria $sth->execute(8) or die "execute failed"; # get an array of the fetched row - since # we are only grabbing one field ... my @row = $sth->fetchrow_array(); # we will store it in a scalar my $field = $row[0]; # print the HTML print header, start_html,start_form, textfield(-name=>'foo',-value=>$field), end_form,end_html, # clean up $sth->finish; $dbh->disconnect;