save html-formatted text to database

Posted by yozhik on Stack Overflow See other posts from Stack Overflow or by yozhik
Published on 2011-01-02T09:49:19Z Indexed on 2011/01/02 9:53 UTC
Read the original article Hit count: 307

Filed under:
|
|

Hi all! I want to save html-formatted text to database, but when I do that it is don't save html-symbols like < / > ' and others This is how I read article from database for editing:

<p class="Title">??????????? ???????:</p>
    <textarea name="EN" cols="90" rows="20" value="<?php echo $articleArr['EN']; ?>" ></textarea>

And this is how I save it to database:

function UpdateArticle($ArticleID, $ParentName, $Title, $RU, $EN, $UKR)
{
    //fetch data from database for dropdown lists
    //connect to db or die)
    $db = mysql_connect($GLOBALS["gl_dbName"], $GLOBALS["gl_UserName"], $GLOBALS["gl_Password"] ) or die ("Unable to connect");

    //to prevenr ????? symbols in unicode - utf-8 coding
    mysql_query("SET NAMES 'UTF8'");
    mysql_set_charset('utf8');
    mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");

    //select database
    mysql_select_db($GLOBALS["gl_adminDatabase"], $db);
    $sql = "UPDATE Articles 
SET AParentName='".$ParentName."', ATitle='".$Title."', RU='".$RU."', EN='".$EN."', UKR='".$UKR."' WHERE ArticleID='".$ArticleID."';";
    //execute SQL-query
    $result = mysql_query($sql, $db);
    if (!$result) 
    {
        die('Invalid query: ' . mysql_error());
    }
    //close database  = very inportant
    mysql_close($db);   
}

Help me please, how can I save such texts properly, Thanx!

© Stack Overflow or respective owner

Related posts about php

Related posts about html