HJey guys, I am trying to read a db and while reading update specific records. Problem is that the while loop works just fine except when I write into the db the while loop stops withy a fetch array error. Here is my code:
# -------------------------------------------------------------------- +------------------------------------------- # -------------------------------------------------------------------- +------------------------------------------- # -------------------------------------------------------------------- +------------------------------------------- # Update the selected Database record sub UpdateDb { $Dbh = DBI->connect($DbConnectionInfo,$DbUserid,$DbPasswd); $Sth = $Dbh->prepare($UpdQuery); $Sth->execute() or $ErrNum = "3007"; $ErrMess = "$DBI::errstr"; $Sth->finish(); $Dbh->disconnect; print "HIER $ErrMess<br>" } # -------------------------------------------------------------------- +------------------------------------------- # -------------------------------------------------------------------- +------------------------------------------- # -------------------------------------------------------------------- +------------------------------------------- # Query the database, and replace the labels with global values if ($ErrNum eq "0") { $RangeQuery = "WHERE $Field LIKE '%$String%' ORDER BY LstNum ASC"; $Dbh = DBI->connect($DbConnectionInfo,$DbUserid,$DbPasswd); $Sth = $Dbh->prepare("SELECT LstNum, LstName31, LstName01, LstSize +, LstDesc31, LstDesc01, LstPurch, LstSaleP, LstSaleW, LstAmount, LstI +nfo FROM $DbTable $RangeQuery"); $Sth->execute or print "$DBI::errstr"; while (($LstNum, $LstName31, $LstName01, $LstSize, $LstDesc31, $Ls +tDesc01, $LstPurch, $LstSaleP, $LstSaleW, $LstAmount, $LstInfo) = $St +h->fetchrow_array){ if ($Field eq "LstName31") { if ($Replace ne "") { print "String: $String<br>"; print "Replace: $Replace<br><br>"; $LstName31Old = $LstName31; $LstName31 =~ s/$String/$Replace/i; print "Updated $LstNum:<br>Old Value: $LstName31Old<br +>New Value: $LstName31<br>"; } if ($NewValue ne "") { print "String: $String<br>"; print "NewValue: $NewValue<br><br>"; $LstName31Old = $LstName31; $LstName31 = $NewValue; print "Updated $LstNum:<br>Old Value: $LstName31Old<br +>New Value: $LstName31<br>"; } if (($Replace eq "") and ($NewValue eq "")) { print "Current $LstNum:<br>Current Value: LstName31 $L +stName31<br>"; } $UpdQuery = "UPDATE $DbTable SET LstName31 + = '$LstName31' WHERE LstNum = '$LstNum'"; UpdateDb(); } } $Sth->finish(); $Dbh->disconnect; } if (($Replace eq "") and ($NewValue eq "")) { print "<br><br>$Mess<br>"; print "No new values received. No records are updated"; } # -------------------------------------------------------------------- +------------------------------------------- # -------------------------------------------------------------------- +------------------------------------------- # -------------------------------------------------------------------- +-------------------------------------------

In reply to DBD problem by Umdurman

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.