From 6b4cfe699a76082754a85aeb4637d9683b3c8f3f Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 22 Apr 1999 04:27:47 +0000 Subject: [PATCH] can add people --- cgi/persons.cgi | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/cgi/persons.cgi b/cgi/persons.cgi index fc9de50..e062124 100755 --- a/cgi/persons.cgi +++ b/cgi/persons.cgi @@ -1,5 +1,5 @@ #!/usr/bin/perl -Tw -# $Id: persons.cgi,v 1.2 1999-04-22 04:12:53 ivan Exp $ +# $Id: persons.cgi,v 1.3 1999-04-22 04:27:47 ivan Exp $ # Copyright (c) 1999 Ivan Kohler. All rights reserved. # This program is free software; you can redistribute it and/or modify it under # the same terms as perl itself @@ -18,7 +18,7 @@ $user = "agent"; $password = "t3chno"; $table = "PERSONS"; -@fields = qw( ID NAME EMAIL AFFILIATION ); +@fields = qw( PERSON_ID NAME EMAIL AFFILIATION ); $cgi = new CGI; @@ -60,15 +60,28 @@ unless ( $cgi->param('magic') ) { #first time through exit; } elsif ( $cgi->param('magic') eq 'new_form' ) { - $cgi->param('ID', 0); + $cgi->param('PERSON_ID', 0); $cgi->param('magic', 'process_form'); &print_form( $cgi, "Add person" ); exit; } elsif ( $cgi->param('magic') eq 'process_form' ) { - print $cgi->header, - "process form stub" + foreach $field ( @fields ) { + if $cgi->param( $field ) + + my $statement = 'INSERT INTO PERSONS ( ', + join(', ', @fields ), + ' ) VALUES ( ', + join( ', ', map { $cgi->param($_) } @fields ), + ' )' + ; + my $sth = $dbh->prepare($statement) + or die $dbh->errstr; + my $rv = $sth->execute; + die $sth->errstr unless $rv; + + print $cgi->header, + "person added?" ; - exit; } sub print_form { @@ -78,7 +91,7 @@ sub print_form { $cgi->start_html($action), $cgi->h1($action), $cgi->start_form, - $cgi->hidden( -name => 'ID' ), + $cgi->hidden( -name => 'PERSON_ID' ), "Name: ", $cgi->textfield( -name => 'NAME' ), "
", "Email: ", $cgi->textfield( -name => 'EMAIL' ), "
", "Affiliation: ", $cgi->textfield( -name => 'AFFILIATION' ), "
", -- 2.11.0