Click to See Complete Forum and Search --> : Submit Order, Form sent to nms ver1.38, need to update mysql also?


redpop
07-09-2006, 06:23 AM
Hi,
I have a site that uses nms formmail ver 1.38 (latest). I would like to update MySQL after the email notification and customer success pages are submitted. I am fairly new at perl, but have given it my best shot. I can update my database with a script I wrote below when sending my form post directly to it, but Don't Understand how or why:

1.) How to do this without some kind of html output.

2.) How to incorporate this or similar coding into nms either as an include(require) or directly coded into nms (does their use strict line prevent me from accessing my database?)


#!/usr/bin/perl -wT

use CGI;
use DBI;
$q = new CGI;

print "Content-type: text/html\n\n";
print "<HTML><HEAD>";
print "<TITLE>perl and SQL Test</TITLE>";
print "</HEAD><BODY>";

# set the data source name
# format: dbi:db type:db name:host
# mysql's default port is 3306
# if you are running mysql on another host or port,
# you must change it
my $dsn = "dbi:mysql:db_name:localhost";

# set the user and password
my $user = "userid";
my $pass = "password";

# now connect and get a database handle
my $dbh = DBI->connect($dsn, $user, $pass) or die;

@namepairs = ();
@valpairs = ();
$howmany = 0;

foreach $i ($q->param()) {
$f{$i} = $q->param($i);
$namepairs[$howmany] = ($i);
$valpairs[$howmany] = $f{$i};
$howmany = $howmany + 1;
}

$count = 0;
while ($count < $howmany) {
if (($valpairs[$count]) eq "0") {
$sth = $dbh->prepare("UPDATE `table` SET `qtyfield` = '0' WHERE `itemidfield` = '$namepairs[$count]'");
$sth->execute;
}
$count = $count + 1;
}

my $dbh->disconnect;

print "</BODY></HTML>";

Thanks