I have CKEditor and want to send its data to the server in order to store it in MySQL. I am able to send source code (data) of CKEditor to the server with jQuery Ajax but when I try to execute my SQL query in order to store it in the database the insert command gives error. I think the main problem here is that CKEditor data contains new lines in it. How to solve this problem?
I have found this question similar to mine, but when I tried it and it didn't work for me. And I didn't understand what does mysql_prep
function do, because it is not standard PHP function.
update 1
The code for the HTML form is following:
$("#save").click(function(){
var data = $( '#editor1' ).val();
$.ajax({
type:"POST",
url:"save.php",
data: "editor1="+data,
timeout:15000,
error:function(XMLHttpRequest, textStatus, errorThrown){
alert("ERROR");
},
success:function(response){
alert("Success: "+response);
}
});
})
And the save.php has following codes:
<?php
include '../config.php'; //connecting to DB
$title='news 1'; $author=1; $date="2011/08/08"; $categories='1,2,3';
$short_text=$_POST['editor1']; $full_text=$_POST['editor1'];
$sql=sprintf('insert into news values(null,"%s",%d,"%s","%s","%s","%s")',$title,$author,$date,$short_text,$full_text,$categories);
mysql_query($sql) or die("Error in $sql");
?>