in reply to Re: Re: Re: Re: Re: Re: Re: Re: Modifying Perl script to write to MySQL??
in thread Modifying Perl script to write to MySQL??

Isn't this is a variable - just a string which changes with each new ad??

Not in this case: $guestbookreal just holds the path and name of the file in which the data of the ad are stored. So you have to read what is in that file, which can be done as follows:

my $content; open FILE, '<', $guestbookreal; # Open a filehandle FILE to $guestbook +real while (<FILE>) { chomp; # delete any EOL character(s) $content .= $_; # Add the next line to the previous parts }

Now $content has the data you need. Then you do:

$sth=$dbh->prepare($content); $sth->execute();

Before anyone notices: I left out all error checking! A real script would be full of or die 'xxxx' statements.

Now as to the basic script you were using. The author himself wrote:
While the free code found at my web site has not evolved much in recent years, the general programming practices and standards of CGI programs have. nms is an attempt by very active programmers in the Perl community to bring the quality of code for these types of programs up to date and eliminate some of the bad programming practices and bugs found in the existing Matt's Script Archive code. I would highly recommend downloading the nms versions if you wish to learn CGI programming. The code you find at Matt's Script Archive is not representative of how even I would code these days.
So do me a favour and go to http://nms-cgi.sourceforge.net/ and replace your script with a more modern and up-to-date version.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Modifying Perl script to write to MySQL??
by bobafifi (Beadle) on Feb 16, 2004 at 21:49 UTC
    I've tried to modify the script as I thought you have suggested:

    http://www.usedflutes.com/countzero.txt

    Does that look like what you had in mind?
    If so, can you please tell me what then becomes of the  $guestbookreal = "/home/flute/usedflutes-www/new_listings.html"; part of the script?

    Thanks again CountZero for helping me out with this.

    -Bob

    p.s. Yes, I have downloaded the nms script and do intend at some point in the not-too-distant-future to update my script. I very much appreciate the encouragement from yourself, Dave and others to do so, thanks.
      You should put the while (<FILE>) { on a line by its own or else it will not be seen because of the comment prior in that line.

      As to what becomes of the $guestbookreal part of the script I have no idea whatsoever. For that I would have to analyze the whole script and sadly I'm lacking in time to do so.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        That worked! !

        There's a couple of strange anomolies:

        - Date field now says "Friday, February 13, 2004"
        - "dt_update," and "dt_create" fields show nothing but zeros

        anyhow, at least NOW the ads post to MySQL (yippie!)
        (whatever's causing those other bugs, that's a different chapter...)

        Many thanks for all your help CountZero! :-)

        -Bob
        >As to what becomes of the $guestbookreal part of the script I have no idea whatsoever.
        >For that I would have to analyze the whole script and sadly I'm lacking in time to do so.

        Unfortunately CountZero, I now know what the answer is! - it's what gets printed every time the script is run....
        I couldn't figure out why I kept getting the same result over and over no matter what I put in the form, and so I tried deleting that $guestbookreal=newlistings line and got a "500 Internal Server Error"

        Bingo!
        explains why the date was showing up as February 13 etc. - because that's the same INSERT string that's been on the new_listings.page since Friday - not what's going through the script!
        anyhow...

        still glad to have been shown that it's possible to connect to MySQL this way (even if it's still not working quite right yet)

        Many thanks CountZero, honestly :-)

        -Bob