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 +); } } ...
Thanks!!!

In reply to How to match elements of array by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.