Wow... first, a major rewrite is in order. I looked over your code from the other post and I realize most of it is from Matt's script archive but I think even you, as a beginner, can write better code than that. That said I offer the following suggestions for your existing code:

It appears you are getting the input from STDIN which doesn't make sense if it is from a form. but if it is working and all you want to do is automate putting the print statement into a database, instead of (or in addition to) all your lines that say print GUEST you would need a line that says something like $insert .= and then the rest of the line. Example:

print GUEST "INSERT INTO `mysql_db` (`Title`, `Email`, `City`, `State` +, `Country`, `URL`, `Date`, `Description`, `rid`, `dt_create`, `publi +sh` ) VALUES ("; } if ($line_breaks == 1) { =~ s/\cM\n/\n/g; } print GUEST ""; print GUEST ", ";

Would become:
my $insert = "INSERT INTO `mysql_db` (`Title`, `Email`, `City`, `State +`, `Country`, `URL`, `Date`, `Description`, `rid`, `dt_create`, `publ +ish` ) VALUES ("; } if ($line_breaks == 1) { =~ s/\cM\n/\n/g; } $insert .= ""; # This can be removed as it doesn't do anythin +g $insert .= ", ";

As you can see, first I initialized $insert which would be done the first time you need to write it and then after that I use the concatinate operator (.=) to add text to $insert. Then when you are done, you just need to change $sth=$dbh->prepare($content); to $sth=$dbh->prepare($insert); and then it should insert your code into the database.

Some suggestions:
I suggest you pick up learning perl (and maybe a few other good books, check the book review section of this site) and rewrite your code. Use CPAN and check out some of it's modules, the documentation is usually quite good. Specifically look at CGI.pm which you can use to create all of your forms and then use the data from said forms to populate the database. (put the information in it) Writing to a file and then reading it again to enter the data into a database is VERY slow and while that may not be a big issue to you now, it might later on. Also problems can arrise if 2 people try and write to your guestbook at the same time. These issues go away when you stop writing to disc all the time.

So maybe get your current version working and then take it upon yourself to rewrite it once it's working. Trust me, it's worth it to write it yourself. With good resources like perl monks as well as the countless books and web tutorials on perl, even someone with no programming experience can learn, it just takes a little time.


In reply to Re: Re: Re: Right answer (wrong question...) by MCS
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.