AL-zami AL-zami - 1 year ago 86
MySQL Question

post method not sending full text

i have a stored procedure to send and fetch blog data to database at the same time:

CREATE DEFINER=`root`@`localhost` PROCEDURE `post_and_fetch_ans`(
IN answerbody longtext,
IN postid int,
IN answerer int)
INSERT INTO `login`.`answers` (answer_body,userpost_post_id,users_user_id) VALUES (answerbody,postid,answerer);
SELECT * FROM `login`.`answers` WHERE userpost_post_id = postid ORDER BY answer_date DESC LIMIT 1;

But my problem is the amount of text data i write on the text editor ,only a few lines are send and store to the database.I am using ajax to send the data to a php page which will store it to database .

var data='answer_body='+CKEDITOR.instances.content.getData()+'&userpost_post_id=<?php echo $contents[0]->post_id;?>&users_user_id=<?php echo $userdata->user_id; ?>';


var obj=$.parseJSON(response);

var str="<div class='styleanswer' >"+obj[0]['answer_body']+'</div><hr>';

$('#answerwrapper pre code').each(function(i, block) {

and verifyanswer.php page is :

require_once '../core/init.php';


if(!empty($answer) && !empty($post_id) && !empty($answerer)){
$db = DB::getInstance();
$result = $db->post_and_fetch("CALL login.post_and_fetch_ans(?,?,?)",array($answer,$post_id,$answerer))->result();
echo json_encode($result);

this line


contains only the partial (very less than actual text) text ,not the full text.So less text is stored in database

an example of the problem is

i send this amount of text to store in DB

enter image description here

but i get only this few lines of text stored in DB

Congratulations to Mathematics SE for being the first site to unlock
this hat, less than 18 hours into the event! Also to Code Review SE
and Blender SE for technically needing only three users each to get
this hat (i.e. at the time that the hat was earned, one user had 16 or
more hats, and two other users had enough hats that the first user

Answer Source

You're not properly encoding the POST data in the Javascript code. Instead of concatenating strings, set the data: option to an object, and jQuery will encode it properly.

var data = {
    answer_body: CKEDITOR.instances.content.getData(),
    userpost_post_id: <?php echo $contents[0]->post_id;?>,
    users_user_id: <?php echo $userdata->user_id; ?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download