Stumpped again!
Cash Perkins
cash at flashcom.net
Sat Mar 11 11:09:53 CST 2000
~sdpm~
Hi SDPM friends,
I guess I'm easily stumpped... but here's the deal. I'm trying to insert
and update rows into a database at the same time a flat file is updated by
my message board. There are two functions below. The appenddata fuction
works perfectly. The writedata generates the orrect sql (if i paste the
printed $sqlstatement into mysql it works correctly) yet, the database is
never updated. I know I'm getting into the if because it prints the
$sqlstatement. Since it uses exactly the same info to connect to the
database and perform the sql as the other working function I don't know what
the heck could be wrong. Can someone point me in the right direction?
Thanks a bundle.
Cash.
#======================================================================#
# writedata #
#======================================================================#
sub writedata {
my($datafile,$r_rows, $selected) = @_;
# Cash Start
if ($datafile eq "$password_file_dir/$password_file" ) {
use DBI;
$dbh = DBI->connect("DBI:mysql:$mySQLdatabase:$mySQLserver",
$mySQLuser, $mySQLpswd);
#prepare and execute SQL statement
foreach (@$r_rows) {
chomp($_);
my ( $pswd, $username, $user_group, $firstname, $lastname, $email1,
$status ) = split(/$split_delim/, $_);
if ( $selected eq $username ) {
$status = ($status == "on" ) ? "active" : "pending";
$sqlstatement = qq~
UPDATE members SET username='$username',
firstname='$firstname',
lastname='$lastname', password='$pswd', email1='$email1',
status='$status', user_group='$user_group'
WHERE username='$selected'; ~;
}
}
print "$sqlstatement\n\n";
$sth = $dbh->prepare($sqlstatement);
$sth->execute || die "Could not execute SQL statement ... maybe
invalid?";
$sth->finish;
}
# Cash Finish
if (open(DATA,">$datafile")) {
flock(DATA,2);
print DATA @$r_rows;
flock(DATA,8);
close(DATA);
chmod(0666,$datafile);
}
else {
my_die("Error in subroutine writedata: Can't open $datafile",$!);
}
}
#======================================================================#
# appenddata #
#======================================================================#
sub appenddata {
my($datafile,$row) = @_;
# Cash Start
if ($datafile eq "$password_file_dir/$password_file" ) {
use DBI;
$dbh = DBI->connect("DBI:mysql:$mySQLdatabase:$mySQLserver",
$mySQLuser, $mySQLpswd);
#prepare and execute SQL statement
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
my $now = sprintf "%4d-%02d-%02d %02d:%02d:%02d\n",
1900+$year,$mon+1,$mday,$hour,$min,$sec;
my ( $pswd, $username, $user_group, $firstname, $lastname, $email1,
$status ) = split(/$split_delim/, $row);
$status = ($status == "on" ) ? "active" : "pending";
$sqlstatement = qq~
INSERT INTO members (key_member_id, username, title, firstname,
lastname,
password, address, country, timezone, city, state, zipcode, homephone,
workphone, sex, email1, email2, url, birthday, icq, msm, aim, photo,
occupation, gaming_experience, comments, status, display_member_info,
block_user_flag, block_user_message, block_user_date, send_newsletter,
charter_member, joined_date, quit_date, last_login, applied_date,
active_character_count, pending_character_count, user_group)
VALUES
('', '$username', '','$firstname', '$lastname', '$password', '', '',
'', '', '', '', '', '', '', '$email1', '', '', '', '', '', '', '',
'', '', '','$status', 'Y', 'N', '', '0000-00-00 00:00:00', 'Y', 'N',
'$now','0000-00-00 00:00:00', '$now', '$now', '', '', '$user_group')~;
$sth = $dbh->prepare($sqlstatement);
$sth->execute || die "Could not execute SQL statement ... maybe
invalid?";
$sth->finish;
}
# Cash Finish
if (open(DATA,">>$datafile")) {
flock(DATA,2);
print DATA "$row\n";
flock(DATA,8);
close(DATA);
}
else {
my_die("Error in subroutine appenddata: Can't open $datafile",$!);
}
}
~sdpm~
The posting address is: san-diego-pm-list at hfb.pm.org
List requests should be sent to: majordomo at hfb.pm.org
If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:
unsubscribe san-diego-pm-list
If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.
More information about the San-Diego-pm
mailing list