As Hippo suggested, here is a simple test cgi that both reads and writes to a database.

#!perl use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use DBI; my $q = CGI->new; my $fname = $q->param('fname'); my $lname = $q->param('lname'); my $email = $q->param('email'); my $action = $q->param('action'); my $dbh = getDbh('c:/temp/web/cgi_test1.db'); #createTable($dbh); # execute once if ($action eq 'Add'){ $dbh->do('INSERT INTO people (fname, lname, email) VALUES (?, ?, ?)' +, undef,$fname, $lname, $email); } elsif ($action eq 'Delete All'){ $dbh->do('DELETE FROM people'); } $dbh->commit(); my $table = join "\n", map { join " | ",@$_ } $dbh->selectall_array('SELECT * FROM people'); my $now = scalar localtime; print $q->header; print << "END_HTML"; <head><title>Test</title></head> <body> People <hr><pre>$table</pre><hr> <form action = "" method="post"> fname <input type="text" name="fname" value="Joe"><br/> lname <input type="text" name="lname" value="Smith"><br/> email <input type="text" name="email" value="joesmith\@somewhere.com" +><br/> <input type="submit" name="action" value="Add"> <input type="submit" name="action" value="Delete All"> </form> $now</body></html> END_HTML sub getDbh { my $dbfile = shift; my $dsn = "dbi:SQLite:dbname=$dbfile"; my $dbh = DBI->connect($dsn, '', '', { PrintError => 0, RaiseError => 1, AutoCommit => 0, FetchHashKeyName => 'NAME_lc', } ) or die $dbh::errstr; }; sub createTable { my $dbh = shift; my $sql = <<'END_SQL'; CREATE TABLE people ( id INTEGER PRIMARY KEY, fname VARCHAR(100), lname VARCHAR(100), email VARCHAR(100) UNIQUE NOT NULL ); END_SQL $dbh->do($sql); $dbh->commit(); };
poj

In reply to Re: Trouble writing to SQLite from CGI on Windows by poj
in thread Trouble writing to SQLite from CGI on Windows by RedJeep

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.