Hi everyone! I'm back playing with Perl but it looks like I will never learn :)
My problem now is the following: I have a script which gathers data from a online form and need to update a table after it. The data is some sort of a form. I have a table with 100 rows, every of which is composed by 3 columns: the first one is the data to eveluate, the second column contains a yes/no selection and the third one provides a alternative evaluation if the answer in the second column is no.
This part works and it looks like the selected data are correctly placed inside three arrays. But now I have problem updating the table, since I only succed in updating one data, instead of them all. My code for the updating part is the following:
sub framerightsave{ my($dbhsource,$dbhinstance,$dbhadmin,$firstfield,$ynfield,$thirdfi +eld,$save,$op) = @_; my(@inst,@altern,@yn,$curent,$curinst,$curalt,$curyn,$htmld,$n,$sa +vedata); @yn = split(/\|/,$ynfield); @altern = split(/\|/,$thirdfield); @inst = split(/\|/,$firstfield); print "<table border=1 bgcolor=#cbe8fc border=0 cellspacing=0 cell +padding=2 width=100%>"; print "<tr bgcolor=#fce7ca><td colspan=4><font size=-1 face=verdan +a >Save evaluations of instances: $instance</font></td></tr>"; print "<tr bgcolor=#fce7ca><td><font size=-1><b>Istanza</td><td><f +ont size=-1><b>Saved evaluation</td><td><font size=-1><b>Alternative +evaluation</td></tr>"; my $mysqldbinstance=$frameinit::MYSQLDBINS; $dsninstance = "DBI:mysql:database=$mysqldbinstance;host=$myhost"; $dbhinstance = DBI->connect($dsninstance, $mysqluser, $mysqlpwd)|| + print "NON RIESCO A CONNETTERMI\n"; while(@inst){ $curent = shift @inst; $curyn = shift @yn; $curaltern = shift @altern; if($curyn =~ /\w+/){ &updatemysql($curent,$curyn,$curaltern); } print "<tr bgcolor=$col><td><font size=-1><b>$curent</td><td>< +font size=-1><b>$curyn</td><td><font size=-1>$curaltern</td></tr>"; } print "</table>"; } sub updatemysql{ my($curent,$curyn,$curaltern) = @_; my($update,$mysqldbinstance,$dsninstance, $dbhinstance, $sthinstan +ce,$rvinstance,$toupdt); my $mysqldbinstance=$frameinit::MYSQLDBINS; $dsninstance = "DBI:mysql:database=$mysqldbinstance;host=$myhost"; $dbhinstance = DBI->connect($dsninstance, $mysqluser, $mysqlpwd)|| + print "NON RIESCO A CONNETTERMI\n"; if($curyn =~ /yes/){ $toupdt= $curyn; } else{ if ($curaltern =~/\w+/) { $toupdt= $curyn.'_'.$curaltern; } else{ $toupdt= $curyn; } } if($curyn =~ /\w+/){ $update = "update inst_3 set u1 = \"$toupdt\" where object = \ +"$curent\""; $sthinstance = $dbhinstance->prepare($update); $rvinstance = $sthinstance ->execute(); if ( !defined($rvinstance) ){ print "exec:$DBI::errstr, $select\n"; } } }
Where am I going wrong? Thanks everyone for the very much needed help

In reply to Problem updating mysql table by remluvr

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.