After reading the previous thread I think what you're asking for is complete code to show you how to dynamically insert results of html forms into a database. Assuming this is the case, here is a simple (untested!) script which does this:
#!/usr/bin/perl -wT use strict; use DBI; use CGI; my $cgi = CGI->new(); print $cgi->header(), # Print header etc. $cgi->start_html(); if($cgi->param()) { # something was submitted my $name = $cgi->param("name") || "Anonymous"; my $message = $cgi->param("message") || ""; if($message) { # If they submitted some message # Make a connection to the database. my $dbh = DBI->connect("DBI:mysql:host=localhost;database=my +_db", "my_id", "my_pass", {AutoCommit => 1, # commit immediately PrintError => 0, RaiseError => 1 ShowErrorStatement => 1 } ); # Prepare the SQL so we can then use it to insert # into the database. Notice that we use ?s instead # of actual values. This means that we can get # DBI to do our actual quoting and saves us a lot # of bother. my $sth = $dbh->prepare("INSERT INTO guestbook (name, message, date) VALUES (?,?,?)"); # Now we execute the SQL. We pass in one value # for each question mark that we put into the # prepare statement up there. DBI will make sure # that our values are properly escaped. $sth->execute($name, $message, scalar(localtime(time))); # This entry has now been added to the database. # Since we (probably) don't need the database # handle anymore, we tidy up by disconnecting. $dbh->disconnect(); # Print something for the user to see. print "Thankyou for your addition to the guestbook."; } print "I think you forgot to add a message"; } print_guestbook(); # You'll have to fill this one out. print_addtoguestbook();# You'll have to fill this one out too. print $cgi->end_html;

I whole-heartedly agree with davorg's advice that you replace your original script with the drop in replacement from nms. This code is free, well written and more secure than Matt's scripts. It is probably easier to improve in the manner you're trying than Matt's scripts will be, too.

Anyway, I hope this now makes sense to you.

jarich


In reply to Re: Right answer (wrong question...) by jarich
in thread Right answer (wrong question...) by bobafifi

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.