我正在编写一个简单的类似 cms 的解决方案来跟踪我的愚蠢想法。一切都很顺利,但我现在在将 Xinha RTE 插件实施到我的应用程序中时遇到了一些困难。
我已经按照他们的现场教程进行操作,它似乎正在工作,但是......
在对文本、标题段落等进行格式化时。虽然标签已正确保存在 mysql 数据库中:
<h1>heading</h1>
<p>text example</p>
它们显示为:
<h1>heading</h1><p>text example</p> (concatenated and NOT formatted , displaying tags in stead)
或者
<p>tesy</p> <h4>fgfg<br /></h4> <h2> </h2>
最后一个示例输出是因为我做了这个更改:
//$postCon = mysql_real_escape_string($postCon);
$postCon = htmlspecialchars($postCon);
那只是因为他们论坛上的某个人说逃避 html 特殊字符是“愚蠢的”——因为 html 标签是由它们组成的。
我很难指定实际问题。因此我的问题有点草率。我希望那里有一些我现在所处的位置,并且可以在正确的方向上提供一些解释或指导。
我现在会去喝咖啡思考这个问题,如果我有任何新的东西,我会带来更新。现在,我将只为您提供执行后期处理的实际脚本。
谢谢,
<?php
include_once 'bin/configDb.php';
include_once 'bin/connectDb.php';
include_once 'header.php';
//get stuff from post
$topicSub = $_POST['topic_subject'];
//$topicSub = mysql_real_escape_string($topicSub);
$topicSub = htmlspecialchars($topicSub);
$topicCat = $_POST['topicCat'];
// $topicCat = mysql_real_escape_string($topicCat);
$sesId = $_GET['username'];
//the form has been posted, so save it
//insert the topic into the topics table first, then we'll save the post into the posts table
$postCon = $_POST['post_content'];
//$postCon = mysql_real_escape_string($postCon);
$postCon = htmlspecialchars($postCon);
$sql = "INSERT INTO
topics(topic_subject, topic_date, topic_cat, topic_by)
VALUES('$topicSub', NOW(), '$topicCat', '$sesId' )";
$result = mysql_query($sql);
if(!$result)
{
//something went wrong, display the error
echo 'An error occured while inserting your data. Please try again later.' . mysql_error();
$sql = "ROLLBACK;";
$result = mysql_query($sql);
}
else
{
//the first query worked, now start the second, posts query
//retrieve the id of the freshly created topic for usage in the posts query
$topicId = mysql_insert_id();
$sql = "INSERT INTO
posts(post_content,
post_date,
post_topic,
post_by)
VALUES
('$postCon', NOW(), '$topicId', '$sesId' )";
$result = mysql_query($sql);
if(!$result)
{
//something went wrong, display the error
echo 'An error occured while inserting your post. Please try again later.' . mysql_error();
$sql = "ROLLBACK;";
$result = mysql_query($sql);
}
else
{
$sql = "COMMIT;";
$result = mysql_query($sql);
//after a lot of work, the query succeeded!
echo 'You have successfully created <a href="topic.php?id='. $topicid . '">your new topic</a>.';
header("location:admin.php");
}
}
include_once 'footer.php';
?>