I am trying to upload some rows to DB

INPUTS CID,MSISDN,Preference,TYPE,SEVERITY "9","9596354636","1","A","2" "9","9596560722","2","A","2" "9","9596560722","2#3#4","A","2" "9","9622526453","3","D","2"

if it is "A" I need to add that number in the particular category as '1'. If the number is already exists in DB then update it on duplicate key of msisdn

my $user_sth = $dbh->prepare("insert into user_master (msisdn,cat0,ca +t1,cat2,cat3,cat4,cat5,cat6,cat7,vip,SAcode,phone_type) values (?,?,? +,?,?,?,?,?,?,?,?,?) on duplicate key update ?"); if ( $opty eq "A" ) { if ( $preference =~ tr/0//) #if pref +erence is 0 make all category as 0 { $cat{'0'} =1; $cat{'1'} =0; $cat{'2'} =0; $cat{'3'} =0; $cat{'4'} =0; $cat{'5'} =0; $cat{'6'} =0; $cat{'7'} =0; $db_update_cmd = "cat0=1"; #,c +at1=0,cat2=0,cat3=0,cat4=0,cat5=0,cat6=0,cat7=0"; } else #or made that category as + one in the DB { my @all_cat = split(/\#/,$pref +erence); foreach my $cat (@all_cat) { $cat{$cat} = 1; $db_update_cmd = $db_u +pdate_cmd."cat$cat=1,"; } chop $db_update_cmd; } my @db_values = (sprintf('%0d', $cat{'0'}), sprintf('%0d',$cat{'1'}),s +printf('%0d', $cat{'2'}), sprintf('%0d',$cat{'3'}),sprintf('%0d', $ca +t{'4'}),sprintf('%0d',$cat{'5'}),sprintf('%0d', $cat{'6'}), sprintf(' +%0d',$cat{'7'})); $user_sth->execute($msisdn,@db_values,0,$SAC,$phone_type,$db_update_cm +d) or die $DBI::errstr;
DBD::mysql::st execute failed: You have an error in your SQL syntax; c +heck the manual that corresponds to your MySQL server version for the + right syntax to use near ''cat1=1'' at line 1 at ./dnd_category_mana +gement_incremental_provisioning.pl line 208, <FD> line 1.

But it returning this error because it taking $db_update_cmd with ''. For example if the preference is 1 the $db_update_cmd = "cat1=1". If I pass that in execute function it taking as  ...... upadte 'cat1=1'; Due to that single quotes its showing error. How can I simplify this


In reply to Error in $sth->execute() by ravi45722

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.