something like this:
#!/usr/bin/perl use strict; use CGI; use HTML::Template; use DBI; my $q = CGI->new; my $dbh = DBI->connect( 'dbi:Pg(RaiseError=>1,Taint=>1):dbname=write;host=loca +lhost', 'user', 'password', ); if ( $q->param('post') eq 'post' ) { #post info to db my $sth_get_text = $dbh->prepare( q{ insert into write (name,text) values (?,?) } ); my $insert = $sth_get_text->execute( $q->param('name'), $q->param( +'text') ); $sth_get_text->finish; $q->redirect('/perl/write.pl'); } else { #display my $sth_get_text = $dbh->prepare( q{ select text,name from write } ); $sth_get_text->execute(); my $text = $sth_get_text->fetchall_arrayref; $sth_get_text->finish; my %hash; my $stuff; foreach my $text_in ( @{$text} ) { push @{ $hash{stuff} }, { text => $text_in->[0], name => $text_in->[1], }; } my $template = HTML::Template->new( filename => 'write.tmpl', die_on_bad_params => 0 ); $template->param(%hash); print $template->output; } $dbh->disconnect;
note that this one also contains a html template loop for extracting the tuples out of DB and displaying them, along with a form

write.tmpl is a template which contains the templater loop info and of course a form which submits to this script with the name and text fields present


In reply to Re: HTML Form Submission & Save to MySQL by drfrog
in thread HTML Form Submission & Save to MySQL by macPerl

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.