Hello,
I am having a rich text editor in my website it works fine when formatting text like bold etc. but the problem is that when i retrieve data from database there is no bold, italic or underline etc.Please help me. you can find the script here.
http://www.dynamicdrive.com/dynamicindex16/richtexteditor/index.htm

Dani AI

Generated

Brief summary: the rich-text editor produces HTML (tags like <b>, <i>, <u>) but those tags are either being removed before storage or encoded/escaped when you print them back. As reported, formatting disappears on retrieval. As hinted, something in your save/load pipeline is changing the data — but simply relying on naive escaping can be brittle. The fastest way to diagnose and fix the problem is a small, focused checklist.

  1. Inspect the database row directly (phpMyAdmin or mysql CLI). Do you see raw tags like <b> in the stored value, encoded entities like &lt;b&gt;, or no tags at all?
  2. If tags are present in the DB but not visible in the browser, view the page source. If you see &lt;/&gt; the output is being escaped (template engine or htmlspecialchars-like code). If tags are absent in the DB, some server-side code stripped them before insert (look for sanitizers or form handling that strips HTML, or check that the editor field is actually posted).
  3. Check the form/editor integration: many editors update a hidden textarea — make sure that field has a name and is submitted.

Recommended approach: store the sanitized HTML (not raw user HTML) and render it as HTML on output. Use parameterized/prepared queries to avoid manual escaping at insert time, and use a whitelist HTML sanitizer to remove dangerous markup (for example, an established library such as HTML Purifier). For XSS guidance, follow OWASP recommendations before allowing any HTML back to users.

Cautions: do not blindly allow script/event attributes; ensure your DB column can hold the content (TEXT/MEDIUMTEXT); if using a template engine that auto-escapes, mark the stored HTML as safe only after sanitization. These steps will preserve formatting while protecting users.

Recommended Answers

All 2 Replies

Hi there,
I think the problem probably lies with your sanitizing methods.
When you insert (or update) the data into the database, make sure that you run the function "addslashes()" on the text from the editor before putting it into your sql. And then when you retrieve it from the database, run the "stripslashes()" method on the text.
That should sort your problem out.

It doesn't work.It only displays text without any kind of formatting the user has done.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.