in reply to Re: Modifying Perl script to write to MySQL??
in thread Modifying Perl script to write to MySQL??
(end excerpt)#!/usr/bin/perl use DBI; # Guestbook Version 2.3.1 + # # Copyright 1996 Matt Wright mattw@worldwidemart.com + # # Created 4/21/95 Last Modified 10/29/95 + # # Scripts Archive at: http://www.worldwidemart.com/scripts/ + # # COPYRIGHT NOTICE + # # Copyright 1996 Matthew M. Wright All Rights Reserved. + # # + # # Guestbook may be used and modified free of charge by anyone so long +as # # this copyright notice and the comments above remain intact. By usin +g this # # code you agree to indemnify Matthew M. Wright from any liability tha +t # # might arise from it's use. + # # + # # Selling the code for this program without prior written consent is + # # expressly forbidden. In other words, please ask first before you tr +y and # # make money off of my program. + # # + # # Obtain permission before redistributing this software over the Inter +net or # # in any other medium. In all cases copyright and header must remain +intact.# # Set Variables $dbh = DBI->connect ("DBI:mysql:host=localhost;database=my_db", "my_id", "my_pass", {PrintError => 0, RaiseError => 1}); $guestbookurl = "http://www.usedflutes.com/confirmation.html"; $sth = $dbh->prepare($guestbookreal); $sth->execute(); $guestlog = "/home/yourname/public_html/guestlog.html"; $cgiurl = "http://64.177.252.244/home/flute/usedflutes-www/cgi-bin/gue +stbook.pl "; $date_command = "/bin/date"; # Set Your Options: $mail = 1; # 1 = Yes; 0 = No $uselog = 0; # 1 = Yes; 0 = No $linkmail = 1; # 1 = Yes; 0 = No $separator = 1; # 1 = <hr>; 0 = <p> $redirection = 1; # 1 = Yes; 0 = No $entry_order = 1; # 1 = Newest entries added first; # 0 = Newest Entries added last. $remote_mail = 1; # 1 = Yes; 0 = No $allow_html = 0; # 1 = Yes; 0 = No $line_breaks = 0; # 1 = Yes; 0 = No # If you answered 1 to $mail or $remote_mail you will need to fill out + # these variables below: $mailprog = '/usr/lib/sendmail'; $recipient = 'listings@usedflutes.com'; $updates = 'updates@usedflutes.com'; # Done # Get the Date for Entry $date = `$date_command +"%A, %B %d, %Y "`; chop($date); $shortdate = `$date_command +"%D %T %Z"`; chop($shortdate); # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<!--(.|\n)*-->//g; unless ($name eq 'username' or $name eq 'url') { $value = ucfirst($value); } if ($allow_html != 1) { $value =~ s/<([^>]|\n)*>//g; } if($name eq 'username') { $FORM{$name} = $value; } else { $FORM{$name} = $dbh->quote($value); } } # Print the Blank Response Subroutines &no_comments unless $FORM{'comments'}; &no_name unless $FORM{'realname'}; # chop comments field down to max if necessary $FORM{'comments'} = substr($FORM{'comments'},0,640) unless (length($FO +RM{'comments'}) <= 640); # URL biz $FORM{'url'} = "''" if $FORM{'url'} eq "'http://'"; # Begin the Editing of the Guestbook File open (FILE,"$guestbookreal") || die "Can't Open $guestbookreal: $!\n"; @LINES=<FILE>; close(FILE); $SIZE=@LINES; # Open Link File to Output open (GUEST,">$guestbookreal") || die "Can't Open $guestbookreal: $!\n +"; for ($i=0;$i<=$SIZE;$i++) { $_=$LINES[$i]; if (/<!--begin-->/) { if ($entry_order eq '1') { } { print GUEST "INSERT INTO `ads_2004` (`Title`, `Email`, `City` +, `State`, `Country`, `URL`, `Date`, `Description`, `rid`, `dt_create +`, `publish` ) VALUES ("; } if ($line_breaks == 1) { $FORM{'realname'} =~ s/\cM\n/\n/g; } print GUEST "$FORM{'realname'}"; print GUEST ", "; if ( $FORM{'username'} ){ my $email_name = $dbh->quote($FORM{'username'}); # if ($linkmail eq '1') { print GUEST $email_name; # } # else { # print GUEST "$FORM{'username'}"; # } print GUEST ", "; } if ( $FORM{'city'} ){ print GUEST "$FORM{'city'}"; } { print GUEST ", "; } if ( $FORM{'state'} ){ print GUEST "$FORM{'state'}"; } { print GUEST ", "; } if ( $FORM{'country'} ){ print GUEST "$FORM{'country'}"; } { print GUEST ", "; } if ($FORM{'url'}) { print GUEST "$FORM{'url'}"; } else { print GUEST "$FORM{'url'}"; } { print GUEST ", "; } if ($separator eq '1') { print GUEST "'$date'"; } else { print GUEST "'$date'"; } { print GUEST ", "; } if ( $FORM{'comments'} ){ print GUEST "$FORM{'comments'}, '', 'NOW()', 0) \n\n"; } if ($entry_order eq '0') { print GUEST "<!--begin-->\n"; } } else { print GUEST $_; } } close (GUEST); $dbh->disconnect; # Log The Entry
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Modifying Perl script to write to MySQL??
by davorg (Chancellor) on Feb 15, 2004 at 08:15 UTC | |
|
Re: Re: Re: Modifying Perl script to write to MySQL??
by CountZero (Bishop) on Feb 15, 2004 at 16:25 UTC | |
by bobafifi (Beadle) on Feb 15, 2004 at 23:25 UTC | |
by bobafifi (Beadle) on Feb 16, 2004 at 00:50 UTC | |
by CountZero (Bishop) on Feb 16, 2004 at 06:41 UTC | |
by bobafifi (Beadle) on Feb 16, 2004 at 15:27 UTC | |
by CountZero (Bishop) on Feb 16, 2004 at 16:36 UTC | |
|