Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks! I did ask this question here before, but I am really stuck with this code. I think my question was misunderstood, but I am here trying again please! The user will be uploading a max of 4 pictures from a form in "@pics", but I need to check if any of these picture names in this array is already in the database. And if any pic name in the array "@pics" match any one found in the database I will not allow the code to proceed to do the INSERT.
I just can think about how to do this, here is my code where I am really crazy and stuck, thanks in advance if any one can help!
... 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 "<br>**$flag_pic**<br>"; if($flag_pic == 0) # only do this if $flag_pic is not true or equa +l to 0. { my $dbh = SQLStuff->connect_mysql(); my $sth = $dbh->prepare("insert into test_add(image_1,image_2,i +mage_3,image_4,image_loc,user) values(?, ?, ?, ?, ?,?)") or &justdie("Can't add data, please try again later! ",$dbh->e +rrmsg); $sth->execute((@pics, undef, undef, undef, undef)[0..3],$path_l +oc[0],$got_user) or &justdie("Can't select from table: ",$dbh->errmsg +); } } ...