<%args> $pua_name $password $pua_active => 'f' <%once> use Crypt::PasswdMD5; use DBI; <%init> my $msg = undef; if ($pua_name eq '') { $msg = "You must specify a username."; } elsif ($password eq '') { $msg = "You must specify a password."; } my $dbh = DBI->connect('dbi:Pg:dbname=pua', 'pua', 'pua') or die "Couldn't connect to database: " . DBI->errstr; my $sth = $dbh->prepare("select max(pua_id) from pua;"); $sth->execute or $m->redirect('new_pua.html', msg => "Unable to insert new pua record: " . $sth->errstr); my $pua_id = 0; $pua_id = $sth->fetchrow_array(); $pua_id ++; if (!$msg) { $msg = 'New pua created.'; my $password_hash = unix_md5_crypt($password); $sth = $dbh->prepare("insert into pua(pua_id, username,password_hash,active) values($pua_id, '$pua_name','$password_hash','$pua_active');"); $sth->execute or $msg = "Unable to insert new pua record: " . $sth->errstr; } $m->comp('new_pua.html', msg => $msg);