Listing 3. add-category.html

%# -*- mmm-classes: mason -*-
% if ($successful_insert) {
<Head><Title>Category added</Title></Head>
<Body>
<H1>Category added</H1>
<P>The category "<% $new_category_name %>" was
added successfully.</P>
</Body>
% } else {
<Head><Title>Error: Category not added</Title></Head>
<Body>
<H1>Error: Category not added</H1>
<P>The category "<% $new_category_name %>" was not added
successfully. Error message: </P>
<pre>
<% $DBI::errstr %>
</pre>
</Body>
% }
<%once>
my $dbh;
</%once>
<%init>
# Connect to the database, if we haven't already
# done so
$dbh = $m->comp("database-connect.comp");
# Now insert the new category
my $sql = "INSERT INTO Categories ";
  $sql .= " (category_name) ";
  $sql .= "VALUES ";
  $sql .= " (?) ";
my $sth = $dbh->prepare($sql);
my $successful_insert = $sth->execute($new_category_name);
</%init>
<%args>
$new_category_name
</%args>