Jump to content

[SOLVED] Sending textarea value with AJAX, how to insert it with Linebreak in MySQL ?


ltrem

Recommended Posts

Not sure if its the right place... but here is the problems  ::)

 

I have a Javascript function that get the value of a textarea and then send it to a php pages with AJAX... here is the URL..

http://www.xxx.com/commentFunction.php?comment=" + document.commentForm.comment.value ;

 

Now, in the PHP... I retrieve the variable with

 

$comment = $_GET["comment"];

 

And then insert the $comment in MySQL.. the problem is that when I retrieve the info from MySQL...there is no Linebreak...? How could I correct that? Thanks

 

 

More information...

 

I tried to do

 

alert(document.commentForm.comment.value);

 

And the Alert message is displayed exactly as in the textarea (with the line break)... It seems that passing that value as a parameter in the URL just sanitize the variable and remove all the line break...??

Thanks for your answer kickstart...

 

While trying to do it with the POST... I found this example -> http://www.captain.at/howto-ajax-form-post-request.php

 

and there I say the encoreURI function!

 

so I did

 

http://www.xxx.com/commentFunction.php?comment=" + encoreURI(document.commentForm.comment.value);

 

And in the PHP I did

 

echo "<td><pre>" . urldecode($_GET["comment"]) . "</pre></td>";

 

Worked like a charm!!!

 

Now I'll try to insert/retrieve from the Database to see how it run!

Archived

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

×
×
  • 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.