dungpt29 Posted March 28, 2013 Share Posted March 28, 2013 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"> <table> <tr> <td width="120" align="right" nowrap="nowrap" valign="top"><strong>Description:</strong></td> <td><textarea id="txtdescription" name="txtdescription"></textarea></td> </tr> <tr> <td align="center" valign="middle"> <input type="button" id="btnAddNew" name="btnAddNew" value="Add New" onclick="btnAddNew_onclick();"/> </td> </tr> </table> </form> <script language="javascript" type="text/javascript"> //<![CDATA[ (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'; myEditor.render(); })(); function btnAddNew_onclick() { $("#frmAddNewShoes").submit(); } //]]> </script> 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); $stmt->execute(); $db->closeConnection(); } } class Application_Model_Admin { public function insertSubAvatar($param1) { Obj_connectDB::insertSubAvatar($param1); } } // In AdministrationController.php public function indexAction() { $admin = new Application_Model_Admin(); if ($this->_request->isPost()) { $txtdescription = $this->_request->getPost("txtdescription"); $admin->insertSubAvatar($txtdescription); } } The table in database is as the following: CREATE TABLE `zensr`.`shoes` ( `description` BLOB NOT NULL ) ENGINE = InnoDB; The stored procedure is as the following: DELIMITER $$ DROP PROCEDURE IF EXISTS `zensr`.`sp_insert_subproduct` $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_insert_subproduct`(IN v_description BLOB) BEGIN insert into shoes (description) values (v_description); END $$ DELIMITER ; 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. Quote Link to comment https://forums.phpfreaks.com/topic/276253-how-to-insert-formatted-text-into-mysql-database/ Share on other sites More sharing options...
annaharris Posted May 2, 2013 Share Posted May 2, 2013 I don't know any accurate solution for this.Just try this<TEXTAREA WRAP="OFF" NAME="DESC" ROWS="15" COLS="60"></TEXTAREA>(I don't change the formatting at all when writing to MySQL)OUTPUT SCREEN:print "<PRE>" . $db->row[0] . "</PRE>n";Where $db->row[0] is what is returned from my query for DESCI hope it may work Quote Link to comment https://forums.phpfreaks.com/topic/276253-how-to-insert-formatted-text-into-mysql-database/#findComment-1427740 Share on other sites More sharing options...
dungpt29 Posted May 2, 2013 Author Share Posted May 2, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/276253-how-to-insert-formatted-text-into-mysql-database/#findComment-1427747 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.