I haven't been able to figure this out. The program is throwing an error when I execute the update statement. All of the other regex expressions seem to work just fine, but when a person has an appostrophe in their name, the sql syntax get's messed up. I tried adding a second apostrophe in front of the one in the person's name, and it WORKS in phpmysql when I run the SQL statement. But when I run it in the following code, it doesn't work????
my $query = "SELECT Name FROM Table WHERE Name= 'Will Tu''ufo''ou'"; my $sth = $dbh->prepare($query); $sth->execute(); while($name = $sth->fetchrow_array) { $originalName = $name; $name =~ s/jr//i; #removes 'jr' from names $name =~ s/III//i; #removes 'III' from names $name =~ s/\s+$//; #removes ' ' from end of name #print $name . "\n"; if ($originalName =~ m/'/) { $originalName =~ s/'/''/g; print $originalName; } $updateQuery = "UPDATE week13dk SET Name = '$name' WHERE Name += '$originalName'"; my $uth = $dbh->prepare($updateQuery); $uth->execute(); }
I love it when a program comes together - jdhannibal

In reply to SQL Statement Not Firing Correctly? by jdlev

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.