...
if(@pics) # this array has a max of 4 pic names
{
my $dbh = SQLStuff->connect_mysql();
my $sth = $dbh->prepare("select * from test_users where user = ? ") or &justdie("Can't select from table: ",$dbh->errmsg);
$sth->execute($got_user_name);
# I am using this thinking that if $flag_pic returns true there is already a duplicated pic in the database and
# I dont have to do the INSERT
my $flag_pic==0;
while (my $row = $sth->fetchrow_hashref())
{
if(($row->{image_name_1} ne "") eq ($pics[0] ne "")){$flag_pic=1;}
if(($row->{image_name_2} ne "") eq ($pics[1] ne "")){$flag_pic=1;}
if(($row->{image_name_3} ne "") eq ($pics[2] ne "")){$flag_pic=1;}
if(($row->{image_name_4} ne "") eq ($pics[3] ne "")){$flag_pic=1;}
}
print "
**$flag_pic**
";
if($flag_pic == 0) # only do this if $flag_pic is not true or equal to 0.
{
my $dbh = SQLStuff->connect_mysql();
my $sth = $dbh->prepare("insert into test_add(image_1,image_2,image_3,image_4,image_loc,user) values(?, ?, ?, ?, ?,?)")
or &justdie("Can't add data, please try again later! ",$dbh->errmsg);
$sth->execute((@pics, undef, undef, undef, undef)[0..3],$path_loc[0],$got_user) or &justdie("Can't select from table: ",$dbh->errmsg);
}
}
...