Hi Monks!
I am working on this code that allows users to upload pictures, to avoid page refreshes And not to have the SQL INSERT duplicating the record I am trying to check if the pictures is already in the database. I am kind of stuck here because of the value of “$flag_pic” been always set to one no matter what. I know I am missing something or it is just lack of sleep. As you can see I check if "@pics" is true first, the max numbers of pics in this array its only 4, but it can be 1 or 2 or 3 pics, its up to the user. As long as one of them are in the database I don’t want allow the insert to happen again. I hope I made my self clear.
Here is the part of the code (sample) I am having this issue:
... if(@pics) { 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); #my (@pic1,@pic2,@pic3,@pic4,$flag_pic); my $flag_pic; while (my $row = $sth->fetchrow_hashref()) { #push @pic1,$row->{image_name_1} || ''; #push @pic2,$row->{image_name_2} || ''; #push @pic3,$row->{image_name_3} || ''; #push @pic4,$row->{image_name_4} || ''; 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";} } #my $check_pic1 = shift(@pic1); #my $check_pic2 = shift(@pic2); #my $check_pic3 = shift(@pic3); #my $check_pic4 = shift(@pic4); print "<br>751**$flag_pic**<br>"; # End check if($flag_pic ne "1") { 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 for looking!

In reply to Duplicity Check Help! 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.