Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: HTML Form Submission & Save to MySQL

by drfrog (Deacon)
on Jan 20, 2005 at 02:43 UTC ( [id://423583]=note: print w/replies, xml ) Need Help??


in reply to HTML Form Submission & Save to MySQL

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://423583]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-04-23 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found