LJ Archive

Listing 5. add-news.html

%# -*- mmm-classes: mason -*-
% if ($successful_insert) {
<Head><Title>News story added</Title></Head>
<Body>
<H1>News story added</H1>
<P>The news story headlined "<% $headline %>" was added
successfully.</P>
</Body>
% } else {
<Head><Title>Error: News story not added</Title></Head>
<Body>
<H1>Error: News story not added</H1>
<P>The news story headlined "<% $headline %>"
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 news story
my $sql = "INSERT INTO Articles ";
  $sql .= " (category_id, headline, body) ";
  $sql .= "VALUES ";
  $sql .= " (?, ?, ?) ";
my $sth = $dbh->prepare($sql);
my $successful_insert = $sth->execute($category_id, $headline, $body);
</%init>
<%args>
$category_id
$headline
$body
</%args>
LJ Archive