嘿,当发送到我的 PHP 页面以保存到数据库时,我似乎在从 tinyMCE 框中获取完整的 HTML 代码时遇到问题。
我的 Ajax 代码是这样的:
console.log('type=' + theType + '&rID=' + theReplyID + '&email=' + $('#email').val() + '&name=' + $('#name').val() + '&fb=' + FB + '&com=' + tinyMCE.activeEditor.getContent());
$.ajax({
type: "post",
url: "post.php",
cache: false,
data: 'type=' + theType + '&rID=' + theReplyID + '&email=' + $('#email').val() + '&name=' + $('#name').val() + '&fb=' + FB + '&com=' + tinyMCE.activeEditor.getContent(),
success: function(data,status){
showMsgBox('Your comment has been posted!','OK','blue');
},
error: function(xhr, desc, err){
showMsgBox('Error while saving comment data','OK','red');
}
});
console.log输出正确的测试数据:
type=C&rID=&email=test@here.com&name=david dev&fb=na&com=<p>this is just a test </p>
<p>here </p>
<p>and here</p>
但是当它保存到我的数据库时,它只有:
<p>this is just a test
我的 PHP 页面如下所示:
<?PHP
$type = $_POST['type']; //R(reply) or C(comment)
$email = $_POST['email'];
$name = $_POST['name'];
$fb = $_POST['fb'];
$comment = $_POST['com'];
$dbhandle = mysql_connect("xx.xxx.xxx.xxx", "xxxxx", "xxxxx") or die(mysql_error());
mysql_select_db("Gvth") or die(mysql_error());
$result = mysql_query("SELECT * FROM UserInfo WHERE Email = '" . $email . "'");
$count = 0;
while($row = mysql_fetch_assoc($result)) {
$count++;
$id = $row["id"];
}
mysql_close($dbhandle);
$dbhandle = mysql_connect("xx.xxx.xxx.xxx", "xxxxx", "xxxxx") or die(mysql_error());
mysql_select_db("Gvth") or die(mysql_error());
$result = mysql_query("INSERT INTO UserComments (UserInfoID,Comment,ImageUploaded,commentID,accepted,dt)
VALUES (" . $id . ",'" . $comment . "','na'," . $id . random_numbers(4) . ",1,'" . date('Y-m-d g:i:s',time()) . "');");
mysql_close($dbhandle);