Forum Moderators: open

Message Too Old, No Replies

Scratching my head on this one

triple inserts mysql perl

         

typomaniac

3:03 am on Aug 24, 2015 (gmt 0)

10+ Year Member Top Contributors Of The Month



I ran a test query to see if the id number was copying to the next table and the following code was causing triple inserts, that is, instead of a simple 1 Pebbles for table number one and 1 BamBam for table number two it would insert 3 lines in each table. The sequencing was right on but inserts in threes wasn't exactly what I was looking for. Anybody have any ideas on this one. In the actual script it will be used in itworked fine but this has me scratching my head. btw, this was run on Xampp if that means anything.
#!"C:\xampp\perl\bin\perl.exe"
use strict;
use CGI qw(:standard);
use DBI;
print"Content-type:text/html\n\n";
use CGI::Carp qw(fatalsToBrowser);
use Time::Local;

$dbh = DBI->connect('dbi:mysql:tablename:localhost','root','passphrase') or die('Couldnt connect');

my $test="test";
my $test2="test2";
my $value="Pebbles";
my $value2="BamBam";


my $state="INSERT INTO ".$test." (name) VALUES (?)";
my $sth=$dbh->prepare($state);
$sth->execute($value);

#my $ddd="(LAST_INSERT_ID()";
my $state="INSERT INTO ".$test2." (id,name) VALUES (LAST_INSERT_ID(),?)";
my $sth=$dbh->prepare($state);
$sth->execute ($value2);

$dbh->disconnect;