Question

I'm using a CKEditor along with a CKFinder. Both work fine. When I browse (or copy directly) an image (or flash) to CKEditor, it's displayed within it and inserted into the MySql database.

Aafter inserting it into MySql database, I'm trying to display it in an HTML table where it isn't displayed and the alternate text is displayed.

The image path after browsing an image through the CKFinder is something like the following.

<img alt="" src="/ckfinder/userfiles/images/1243_SS_2502.jpg" style="width: 490px; height: 618px;" />

The contents inserted into the database is as follows.

&lt;img alt=&quot;\&amp;quot;\&amp;quot;&quot; data-cke-saved-src=&quot;\&quot; 

src=&quot;\&amp;quot;/ckfinder/userfiles/images/1243_SS_2502.jpg\&amp;quot;&quot; st  yle=&

quot;\&amp;quot;width:&quot; 490px;=&quot;&quot; height:=&quot;&quot; 618px;\&quot;= quot;&quot;&gt;

Tried with htmlentities() still it doesn't work. While dealing the same with JSP using JSTL/EL, I had to do the following.

<c:out value="${str}" default="No content found." escapeXml="false"/>

escapeXml="false", where str written in EL was a java.lang.String holding the Oracle clob data after conversion.

What is the way to get around the situation in PHP? Both CKEditor and CKFinder work fine for me.


$ckeditor = new CKEditor();
$ckeditor->basePath = 'ckeditor/';
$ckeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html';
$ckeditor->config['filebrowserImageBrowseUrl'] = 'ckfinder/ckfinder.html?type=Images';
$ckeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash';
$ckeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
$ckeditor->config['filebrowserImageUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
$ckeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
$ckeditor->editor('description', $ed_about_us);

Edit:

<?php include_once("Lock.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Wagafashion</title>

<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
<link rel="stylesheet" href="css/template.css" type="text/css"/>
<!--<script type="text/javascript" language="javascript" src="ckeditor/ckeditor.js"></script>-->
<script src="js/jquery-1.6.min.js" type="text/javascript"></script>        
<script src="js/languages/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>

<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script><script>
    jQuery(document).ready(function(){
        // binds form submission and fields to the validation engine
        jQuery("#dataForm").validationEngine();
    });            
</script>

<script language="javascript" type="text/javascript">
    function deleteSingle(id)
    {       
        var delId=confirm("About us with the id "+id+" is about to be deleted permanently.\n\nAttention : This action will never be undone!\n\nAre you sure...???");        
        return(delId==true?true:false);
    }

</script>

</head>

<body>
<?php
    include_once("Connection.php");
    include_once("ckeditor/ckeditor.php");
    $con=new Connection();
    $con->get_connection();

    $ed_about_us="";
    $flag=-1;
    $msg="";

    if(isset($_POST['btnSubmit']))
    {
        $act=trim($_POST['param_action']);
        $about_us=$_POST['cms_description'];        

        if($act=="add")
        {   
            $res=$con->get_data("select count(*) as cnt from cms"); 
            $cnt_cmt=mysql_result($res, 'cnt');

            if($cnt_cmt==0)
            {
                $flag=$con->iud("insert into cms (about_us)values('".mysql_real_escape_string(urlencode($about_us))."')");              
            }
            else
            {
                $flag=$con->iud("update cms set about_us='".mysql_real_escape_string(urlencode($about_us))."'");
            }

            if($flag==1)
            {
                $msg="Insertion done successfully.";        
            }
            else if($flag==0)
            {
                $msg="Insertion failed - reason : ".mysql_errno()." : ".mysql_error();  
            }
        }
        else if($act=="edit")
        {
            $cms_id=$_POST['cms_id'];
            $flag=$con->iud("update cms set about_us='".mysql_real_escape_string(urlencode($about_us))."' where id=".$cms_id."");               
            if($flag==1)
            {
                $msg="About us has been updated successfully.";
            }
            else if($flag==0)
            {
                $msg="Updation failed - reason : ".mysql_errno()." : ".mysql_error();   
            }           
        }
    }           
    else if(isset($_GET['ed_id']))
    {
        $ed_res=$con->get_data("select about_us from cms where id=".$_GET['ed_id'].""); 

        while($row=mysql_fetch_assoc($ed_res))
        {
            $ed_about_us=$row['about_us'];      
        }
    }   
    else if(isset($_GET['del_id']))
    {
        $flag=$con->iud("update cms set about_us='' where id=".$_GET['del_id']);
        if($flag==1)
        {
            $msg="About us been deleted successfully.";
        }
        else if($flag==0)
        {
            $msg="Can not delete - reason : ".mysql_errno()." : ".mysql_error();    
        }
    }
    else if(isset($_POST['btnDelete']))
    {
        $set_del=$_POST['setDel'];
        $flag=$con->iud("update cms set about_us='' where id in($set_del)");
        $size=sizeof(split(",", $set_del));

        if($flag==1)
        {
            if($size==1)
            {
                $msg="1 row deleted.";  
            }
            else
            {
                $msg=$size." rows deleted.";    
            }           
        }
        else if($flag==0)
        {
            $msg="Can not perform deletion - reason : ".mysql_errno()." : ".mysql_error();  
        }       
    }
?>

    <?php include("tamplate/Template1.php");?>
        <h2>About Us</h2>
    <?php include("tamplate/NewTemplate.php");?>

    <?php
        if($flag==1)
        {        
            echo "<p>";
            ?>
                <!--[if !IE]>start system messages<![endif]-->
                <ul class="system_messages">                                     
                    <li class="green"><span class="ico"></span><strong class="system_title"><?php echo $msg; ?></strong></li>                    
                </ul>
                <!--[if !IE]>end system messages<![endif]-->
            <?php               
            echo "</p>";
        }
        else if($flag==0)
        {     
            echo "<p>";
            ?>
                <!--[if !IE]>start system messages<![endif]-->
                <ul class="system_messages">                    
                    <li class="red"><span class="ico"></span><strong class="system_title"><?php echo $msg; ?></strong></li>                                        
                </ul>
                <!--[if !IE]>end system messages<![endif]-->
            <?php               
            echo "</p>";    
        }
    ?>
<img alt=\"\" src="/ckfinder/userfiles/images/1243_SS_2502.jpg" style=\"width: 490px; height: 618px;\" />
      <!--[if !IE]>start forms<![endif]-->
    <form action="<?php $_SERVER['PHP_SELF']; ?>" id="dataForm" name="dataForm" method="post" class="search_form general_form">
        <!--[if !IE]>start fieldset<![endif]-->
        <fieldset>
            <!--[if !IE]>start forms<![endif]-->
            <div class="forms">

            <!--[if !IE]>start row<![endif]-->
            <div class="row">   
            <?php
                $ckeditor = new CKEditor();
                $ckeditor->basePath = 'ckeditor/';
                $ckeditor->config['filebrowserBrowseUrl'] = 'ckfinder/ckfinder.html';
                $ckeditor->config['filebrowserImageBrowseUrl'] = 'ckfinder/ckfinder.html?type=Images';
                $ckeditor->config['filebrowserFlashBrowseUrl'] = 'ckfinder/ckfinder.html?type=Flash';
                $ckeditor->config['filebrowserUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
                $ckeditor->config['filebrowserImageUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
                $ckeditor->config['filebrowserFlashUploadUrl'] = 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
                $ckeditor->editor('cms_description', urldecode($ed_about_us));

            ?>             

            <!--[if !IE]>start row<![endif]-->
            <div class="row">
                <div class="buttons">                                                                                                                                                   
                        <span class="button send_form_btn"><span><span>Submit</span></span><input type="submit" value="Submit" id="btnSubmit" name="btnSubmit" onclick="return validate();"></span>                    
                </div>
            </div>
            <!--[if !IE]>end row<![endif]-->
            </div>
        </fieldset>

        <!--[if !IE]>end fieldset<![endif]-->                
        <input type="hidden" id="param_action" name="param_action" value="

            <?php
                if(isset($_GET['ed_id']))
                {
                    echo "edit";        
                }
                else
                {
                    echo "add"; 
                }
            ?>
            " />

            <input type="hidden" id="cms_id" name="cms_id" value="<?php echo isset($_GET['ed_id'])?$_GET['ed_id']:"";?>" />            
    </form>            

    <?php include("tamplate/Template2.php");?>
        <h2>About Us</h2>
    <?php include("tamplate/NewTemplate1.php");?>   


    <form action="<?php echo $_SERVER['PHP_SELF'];?>" id="mainForm" name="mainForm" method="post">                                                

        <?php include("tamplate/ExtraTemplate.php");?>      

            <table cellpadding="0" cellspacing="0" width="100%">
                <tbody>
                <th style="width: 10px;">Check</th>
                <th style="width: 450px;">About Us</th>                
                <th style="width: 10px;">Actions</th>

                <?php

                    $get_data=$con->get_data("select id, about_us from cms order by id");
                    $cnt=1;$flag='';

                    while($data_row=mysql_fetch_assoc($get_data))
                    {
                        extract($data_row); 
                        $cnt%2==0?$flag="second":$flag="first";
                        ++$cnt;

                        echo "<tr class='$flag'>";
                        echo "<td><input type='checkbox' name='chk' value='$id'></td>";
                        echo "<td>".urldecode($about_us)."</td>";

                        echo "<td><div class='actions'><ul><li><a href='".$_SERVER['PHP_SELF']."?ed_id=$id' class='action2'></a></li>";
                        echo "<li><a href='".$_SERVER['PHP_SELF']."?del_id=$id&table_name=cms&pri=id' onclick='return deleteSingle($id);' class='action4'></a></li></ul></div></td>";
                        echo "</tr>";
                    }
                ?>

                </tbody>
            </table>    
            <input type='hidden' id='setDel' name='setDel'/>
            <?php include("tamplate/Template3.php");?>         
    </form>
    <?php include("tamplate/Template4.php");?> 
</body>
</html>
Was it helpful?

Solution

Did you try to use html_entity_decode() to display the contents ? It will decode the encoded html for better output. Reference here

Edit
Change your query to the following

insert into cms (about_us) values ('".mysql_real_escape_string(urlecode(stripslashes($about_us)))‌​."')

When you get it from database it use

urldecode($value)

Where $value is the block you got from database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top