Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-05-20 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found