Jump to content


This topic is now archived and is closed to further replies.


how to insert formatted text into MySQL database

Recommended Posts

I am trying to build a website based on:

1) MySQL 5.5.27

2) PHP 5.4.7

3) Zend Framework 1.12.0


I am buiding a form that contains a rich text editor YUI (Yahoo User Interface) as the following:


<form method="post"  action="<?php echo $this->baseUrl() . '/administration/index/?activemnu=mnuCon&subatmnu=mnuShoes'?>" id="frmAddNewShoes" name="frmAddNewShoes" enctype="multipart/form-data">
<tr>											             <td width="120" align="right" nowrap="nowrap" valign="top"><strong>Description:</strong></td>
    <td><textarea id="txtdescription" name="txtdescription"></textarea></td>    
    <td align="center" valign="middle">
       <input type="button" id="btnAddNew" name="btnAddNew" value="Add New" onclick="btnAddNew_onclick();"/>



<script language="javascript" type="text/javascript">

(function() { 
	    //Setup some private variables 
	    var Dom = YAHOO.util.Dom, 
	        Event = YAHOO.util.Event; 
	        //The SimpleEditor config 
	        var myConfig = { 
	            height: '200px', 
	            width: '400px', 
	            dompath: true, 
	            focusAtStart: true,				 
		    animate: true,
		    handleSubmit: true
	    //Now let's load the SimpleEditor.. 
	    var myEditor = new YAHOO.widget.SimpleEditor('txtdescription', myConfig); 
		myEditor._defaultToolbar.buttonType = 'basic';

function btnAddNew_onclick()



Connecting to database to insert description into table as the following:


class Obj_connectDB
	protected static function ketnoiDB()

		$options = array(Zend_Db::AUTO_RECONNECT_ON_UNSERIALIZE  => true);
		$params  = array(
    			'host'           =>  'localhost',
                        'username'       =>  'root',
                        'password'       =>  '',
                        'dbname'         =>  'zensr',
                        'options'        =>  $options);
		$db = Zend_Db::factory('Pdo_Mysql', $params);
		return $db;

	public static function insertSubAvatar($param1)
		$db = self::ketnoiDB();
		$stmt = new Zend_Db_Statement_Pdo($db,"call sp_insert_subproduct(:v_description)");                                                              															   																	     																		 																		 																		 																	$stmt->bindParam(":v_description", $param1, PDO::PARAM_LOB);

class Application_Model_Admin
    public function insertSubAvatar($param1)

// In AdministrationController.php
public function indexAction()
    $admin = new Application_Model_Admin();

    if ($this->_request->isPost())
        $txtdescription = $this->_request->getPost("txtdescription");



The table in database is as the following:


CREATE TABLE `zensr`.`shoes` (
  `description` BLOB NOT NULL



The stored procedure is as the following:



DROP PROCEDURE IF EXISTS `zensr`.`sp_insert_subproduct` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_insert_subproduct`(IN v_description BLOB)


  insert into shoes (description) values (v_description);

END $$




Running the code, I find that description field is empty meaning it contains 0 Bytes when I input something to insert value of rich text editor into description field.

How do I edit PHP code to insert successfully?

Please help me solve this problem.





Share this post

Link to post
Share on other sites

I don't know any accurate solution for this.
Just try this
(I don't change the formatting at all when writing to MySQL)

print "<PRE>" . $db->row[0] . "</PRE>n";

Where $db->row[0] is what is returned from my query for DESC

I hope it may work

Share this post

Link to post
Share on other sites

Hi annaharris,

I found out the solution for this problem by myself weeks ago. And it works fine.

Thank you very much for your care, annaharris!

By the way, anyone who has the same problem can reply to me and I am ready to share my experience.

Share this post

Link to post
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.