#!/usr/bin/perl -Tw
-# $Id: persons.cgi,v 1.1 1999-01-27 09:55:05 ivan Exp $
+# $Id: persons.cgi,v 1.4 1999-04-22 04:33:05 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
use CGI::Carp qw(fatalsToBrowser);
use DBI;
-$data_source = "DBI:mysql:test";
-$user = "ivan";
-$password = "";
+$data_source = "DBI:mysql:technostate";
+$user = "agent";
+$password = "t3chno";
$table = "PERSONS";
-@fields = qw( ID NAME EMAIL AFFILIATION );
+@fields = qw( PERSON_ID NAME EMAIL AFFILIATION );
$cgi = new CGI;
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"
+
+ my $field;
+ foreach $field ( @fields ) {
+ if ( $cgi->param( $field ) ) {
+ $cgi->param( $field ) =~ /^(.*)$/;
+ $cgi->param( $field, $1);
+ }
+ }
+ 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 {
$cgi->start_html($action),
$cgi->h1($action),
$cgi->start_form,
- $cgi->hidden( -name => 'ID' ),
+ $cgi->hidden( -name => 'PERSON_ID' ),
"Name: ", $cgi->textfield( -name => 'NAME' ), "<BR>",
"Email: ", $cgi->textfield( -name => 'EMAIL' ), "<BR>",
"Affiliation: ", $cgi->textfield( -name => 'AFFILIATION' ), "<BR>",