Help required: PHP CODE

Discussion in 'PHP' started by anosh, Dec 20, 2009.

  1. #1
    Can someone please help me to write a php code to update mysql.

    hint: "articles_content" is a table, "subject" is a field in that table

    I wish to replace the character " ‘ " to " ' " in the subject area of the table as ‘ is not supported by xml.

    mysql code:
    update articles_content set subject = replace(subject,"‘", "'");

    I created a php file like below. But getting error message due to excess usage of quotes and brackets.

    <?php
    mysql_query = "(update articles_content set subject = replace(subject,"‘", "'"))";
    ?>

    Can you please advise me to correct the above code.
     
    anosh, Dec 20, 2009 IP
  2. NodLemon

    NodLemon Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $query = mysql_query("UPDATE articles_content SET subject = replace(subject, '`', '\'')") or die(mysql_error());
    PHP:
    Try and let us know the outcome.
     
    NodLemon, Dec 20, 2009 IP
  3. xmart

    xmart Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Always use \ before any quotation mark which is not for the code but for the value. Let me know if it solved the problem by following the above solution by NodLemon. If, not then I will write alternate for you (PHP is fun for coding).
     
    xmart, Dec 20, 2009 IP
  4. anosh

    anosh Active Member

    Messages:
    122
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    Thanks NodLemon! It works.

    Hi XMART, I wish to learn the alternate code. Please post it here. It may help others also.
     
    Last edited: Dec 20, 2009
    anosh, Dec 20, 2009 IP