This should get you started. You have stated in the CB that this is a homework assignment - i always recommend that you talk to your teacher/instructor/professor instead of handing them the code we provide, because you are not going to have our help when the exam rolls around. ;)
#!/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;
As you can see, this is just an example. It is up to you to make this work for your problem. If you have more questions, please show us the code you have written so far. Good luck. :)

(update - added shebang line to include taint option)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Populating HTML form fields from Database by jeffa
in thread Populating HTML form fields from Database by peacemaker1820

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.