Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question insert HTML into Database and keeping formating

    ok I am work on a application that inserts HTML that was done with CKeditor found here http://cksource.com/ckeditor pretty simple to install and seems to work great other then when i click save it removes all the HTML formatting and turns it into a blob of run together text. I have tried man different things and still nothing seems to work

    any help would be great here is my code


    PHP Code:
    <?php
     
    // this starts the session 
     
     
        
    include('../../system.php');

    $get_page=mysql_query("SELECT * FROM ttd_special_offers WHERE id=1")  or die (mysql_error());
    $r=mysql_fetch_assoc($get_page);

    $html $r['offer'];

    if(isset(
    $_POST["Submit"])){
    $editor_data $_POST'offer' ];
    $clean_data=htmlentities($editor_data);
    $p_data=$clean_data;

    $up_data="update `ttd_special_offers` SET offer='$p_data' WHERE id=1";
    mysql_query($up_data) or die (mysql_error());

    }
        
    ?>

    <!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>
    <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
    <link rel="stylesheet" type="text/css" href="../css/config.css">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>

    <form action='page_manager.php?id=<?php echo $g_id ;?>' method='POST' name='offer_page'>
        <input type="hidden" name="id" value="id">
        <table width="100%" class="configuration"  bgcolor="#F2F2F2" align="center">
          <tr>
            <th>Special Offers</th>
            <th>
              <table width="100%">
                <tr>
                  <td align="center">
                    <input type="button" value="Close Configuration" onClick="window.location.replace('../frames/home.php');" name="close" class="buttonsubmit">
                  </td>
                   <td>
                      
                  </td>
                </tr>
              </table>
            </th>
          </tr>
          <tr>
            <td width="25%" class="c_col_left" valign="top">Offer 1
            </td>
            <td width="75%" align="center" class="c_col_right" valign="top">
            <textarea  class="ckeditor"  cols="60" rows="20" name="offer" id="offer"><?php echo $html ;?></textarea><script type="text/javascript">
        window.onload = function()
        {
            CKEDITOR.replace( 'offer' );
        };
    </script>
            
            </td>
          </tr>
          <tr>
            <th width="100%" colspan="2">
              <p style="text-align: center">
              <input type="Submit" value="Submit" name="Submit" class="buttonsubmit">
            </th>
          </tr>
        </table>
      </form>

    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    because ur using htmlentities..........

  • #3
    New Coder
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    8
    Thanked 0 Times in 0 Posts
    even with out it strips the HTML content

    this is what i get without

    here is a example say i use

    Code:
    <p>
    	blah blah blah&nbsp;<a href="http://google.com">http://google.com</a>&nbsp;<span style="font-size:24px;">some big text now this is what i &nbsp;get</span></p>
    that in turn when i click submit does this

    in the database

    blah blah blah http://google.com some big text now this is what i get

    Quote Originally Posted by Adee View Post
    because ur using htmlentities..........
    Last edited by jokerswild; 11-19-2011 at 06:08 AM.

  • #4
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    Hi,

    I've used ckeditor before with no problems.

    Have you tried just inserting the post['offer'] straight to the db? This will give you the raw input then you could build it up bit by bit, like the next step would be to escape the input with mysql_real_escape_string(), then if that's still adding it fine then you do the next step (whatever that me be that you want to do).

    I simply passed my posted textarea input (ckeditor) to my db class, escaped as above and saved to the db. All HTML was saved as expected.

    Hope this works for you

  • #5
    New Coder
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    8
    Thanked 0 Times in 0 Posts
    yes I have tried straight POST...still striping the content i dont know why or understandably why....that when i started looking into other options

    Quote Originally Posted by loki421 View Post
    Hi,

    I've used ckeditor before with no problems.

    Have you tried just inserting the post['offer'] straight to the db? This will give you the raw input then you could build it up bit by bit, like the next step would be to escape the input with mysql_real_escape_string(), then if that's still adding it fine then you do the next step (whatever that me be that you want to do).

    I simply passed my posted textarea input (ckeditor) to my db class, escaped as above and saved to the db. All HTML was saved as expected.

    Hope this works for you

  • #6
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    Are you pasting into the textarea? Have you tried typing directly into the textarea and posting like that?

    Without seeing your setup it's a bit tricky to figure out.

    Like I say, I've never had any trouble with ckeditor, it works 'straight out of the box' and posted html to the db with no problems...

    Don't know what else to suggest dude? :s


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •