TinyMCE和php问题

发布于 2024-12-01 09:47:56 字数 6832 浏览 1 评论 0原文

好的,昨天我终于让 TinyMCE 在我的网站上运行了。 我还为其下载了一个提供代码突出显示的插件,但该插件似乎会引起一些“混乱”。

使用过的人都知道,TinyMCE 使用 进行用户输入。好吧,我为它下载的代码荧光笔插件也是如此。到目前为止我从未使用过textarea,但看起来你不能将一个文本区域嵌套在另一个文本区域中。 如果我使用插件将代码示例添加到文本中,TinyMCE 似乎认为文章以插件编写的文本区域的结束标记结束,而不是文章底部的结束标记。 谁能推荐一个更好的插件?

至于PHP,那让我不知所措。我的代码昨天可以立即运行,但是当我今天尝试使用它时,它就超时了。我所做的只是对加载到 TinyMCE 中的记录进行 mysql 更新。 我知道不是 mysql 导致了这个问题,因为我仍然可以使用 phpmyadmin 登录并处理那里的任何数据库。 我不知道从哪里开始查找故障,因此如果有人可以提供指导,我将不胜感激。

作为记录,这是我尝试提交表单时遇到的错误及其后面的 php 代码:

Warning: PDO::__construct() [pdo.--construct]: [2002] A连接尝试失败,因为连接方没有(尝试通过 tcp://localhost:3306 连接)位于第 16 行的 D:\xampp\htdocs\logansarchive\admin\articlework.php 致命错误:在第 0 行 D:\xampp\htdocs\logansarchive\admin\articlework.php 中超出了最大执行时间 60 秒

代码根据用户选择的操作动态生成一个表单(创建一个表单)新文章或编辑现有文章)。

<?php
    switch($action) {
        case "Edit":
            $query = "SELECT * FROM Articles WHERE ArticleTitle = '".$target."'";
            $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());
            if (mysql_num_rows($result) > 0) {
                list($ArticleID, $Category, $ArticleDate, $ArticleTitle, $ArticleContent) = mysql_fetch_row($result);
                    $cat = $Category;
                    $title = $ArticleTitle;
                    $content = $ArticleContent;
            }

            $query = "SELECT CategoryName FROM Categories WHERE DeletedYN = 'No'";
            $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());

            echo "<form name=\"editarticle\" method=\"post\" action=\"articlework.php\">".
                "<table>".
                "<tr>".
                "<td>Article Title<br /><input type=\"text\" name=\"article_title\" value=\"".$title."\" style=\"width: 300px;\" /></td>".
                "<td>Category<br />".
                "<select name=\"article_cat\">".
                "<option selected value=\"".$cat."\">".$cat."</option>".
                "<option>----------------------</option>";
                if (mysql_num_rows($result) > 0) {
                    while($row = mysql_fetch_array($result)) {
                        echo "<option value=\"".$row['CategoryName']."\">".$row['CategoryName']."</option>";
                    }
                }
            echo "</td>". 
                "</tr>".
                "<tr>".
                "<td colspan=\"2\"><textarea id=\"article_content\" name=\"article_content\" rows=\"15\" cols=\"80\" style=\"width: 80%;\">".$content."</textarea>".
                "<tr>".
                "</table>".
                "<div class=\"RightAlign\">".
                "<input type=\"submit\" name=\"btnSubmit\" value=\"Update Article\" />".
                "<input type=\"hidden\" name=\"srctitle\" value=\"".$title."\" />".
                "<input type=\"hidden\" name=\"action\" value=\"".$action."\" /></div>".
                "</form>";
        break;
        case "New":
            echo "<form name=\"newarticle\" method=\"post\" action=\"articlework.php\">".
                "<table>".
                "<tr>".
                "<td>Article Title<br /><input type=\"text\" name=\"article_title\" style=\"width: 300px;\" /></td>".
                "<td>Category<br />".
                "<select name=\"article_cat\">";    

                $query = "SELECT CategoryName FROM Categories WHERE DeletedYN = 'No'";
                $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());
                if (mysql_num_rows($result) > 0) {
                    while($row = mysql_fetch_array($result)) {
                        echo "<option value=\"".$row['CategoryName']."\">".$row['CategoryName']."</option>";
                    }
                }
            echo "</td>".
                "</tr>".
                "<tr>".
                "<td colspan=\"2\"><textarea id=\"article_content\" name=\"article_content\" rows=\"15\" cols=\"80\" style=\"width: 80%;\"></textarea></td>".
                "</tr>".
                "</table>".
                "<div class=\"RightAlign\">".
                "<input type=\"submit\" name=\"btnSubmit\" value=\"Create Article\" />".
                "<input type=\"hidden\" name=\"action\" value=\"".$action."\" /></div>".
                "</form>";
        break;
    }
?>

这是在数据库中执行此操作的代码:

<?php
    $action = $_REQUEST["action"];
    $target = $_REQUEST["target"];
    $srctitle = $_POST["srctitle"];
    $title = $_POST["article_title"];
    $cat = $_POST["article_cat"];
    $content = $_POST["article_content"];

    // Set database server access variables:
    $host = "localhost";
    $user = "root";
    $pass = "root";
    $db = "logansarchive";

    // Open connection
    $dbh = new PDO('mysql:host='.$host.';dbname='.$db, $user, $pass);   

    $date = date('Y-m-d H:i:s');
    switch ($action) {
        case "Edit":
            $query = $dbh->prepare("UPDATE Articles ".
                "SET ArticleTitle = :title, Category = :cat, ArticleDate = :date, ArticleContent = :content ".
                "WHERE ArticleTitle = :srctitle");
            $query->bindParam(':title', $title);
            $query->bindParam(':cat', $cat);
            $query->bindParam(':date', $date);
            $query->bindParam(':content', $content);
            $query->bindParam(':srctitle', $srctitle);
            $query->execute();
        break;
        case "New":
            $query = $dbh->prepare("INSERT INTO Articles(Category, ArticleDate, ArticleTitle, ArticleContent) ".
                "VALUES(:cat, :date, :title, :content)");
            $query->bindParam(':cat', $cat);
            $query->bindParam(':date', $date);
            $query->bindParam(':title', $title);
            $query->bindParam(':content', $content);
            $query->execute();
        break;
        case "Delete":
            if ($target != "") {
                $query = $dbh->prepare("UPDATE Articles ".
                    "SET DeletedYN = :del ".
                    "WHERE ArticleTitle = :title");
                $query->bindValue(':del', "Yes");
                $query->bindParam(':title', $target);
                $query->execute();
            }
            else {
                header("Location: index.php?result=failed");
            }
        break;
    }

    header("Location: index.php?result=success");
?>

Ok so yesterday I finally got TinyMCE working on my site.
I also downloaded a plugin for it that offered code highlighting, but the plugin seems to cause some "confusion".

As we who have used it know, TinyMCE uses a <textarea></textarea> for user input. Well, so does the code highlighter plugin I downloaded for it. I've never used textarea until now, but it looks like you can't nest one within the other.
If I add a code sample to my text with the plugin, TinyMCE seems to think the article ends at the closing tag for the textarea that the plugin wrote, rather than the one at the bottom of the article.
Can anyone recommend a better plugin?

As for PHP well, that's got me at a loss. My code was working instantly yesterday, but as soon as I tried to use it today, it times out. All I tried to do was a mysql update on the record that was loaded into TinyMCE.
I know it wasn't mysql that caused the problem because I can still login with phpmyadmin and work on any database there.
I have no idea where to begin with fault finding so if anyone can provide guidance, that would be greatly appreciated.

For the record, here's the error I'm getting when I try to submit my form, and the php code behind behind it:

Warning: PDO::__construct() [pdo.--construct]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in D:\xampp\htdocs\logansarchive\admin\articlework.php on line 16
Fatal error: Maximum execution time of 60 seconds exceeded in D:\xampp\htdocs\logansarchive\admin\articlework.php on line 0

The code dynamically generates a form based on which action was selected by the user (create a new article or edit an existing one).

<?php
    switch($action) {
        case "Edit":
            $query = "SELECT * FROM Articles WHERE ArticleTitle = '".$target."'";
            $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());
            if (mysql_num_rows($result) > 0) {
                list($ArticleID, $Category, $ArticleDate, $ArticleTitle, $ArticleContent) = mysql_fetch_row($result);
                    $cat = $Category;
                    $title = $ArticleTitle;
                    $content = $ArticleContent;
            }

            $query = "SELECT CategoryName FROM Categories WHERE DeletedYN = 'No'";
            $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());

            echo "<form name=\"editarticle\" method=\"post\" action=\"articlework.php\">".
                "<table>".
                "<tr>".
                "<td>Article Title<br /><input type=\"text\" name=\"article_title\" value=\"".$title."\" style=\"width: 300px;\" /></td>".
                "<td>Category<br />".
                "<select name=\"article_cat\">".
                "<option selected value=\"".$cat."\">".$cat."</option>".
                "<option>----------------------</option>";
                if (mysql_num_rows($result) > 0) {
                    while($row = mysql_fetch_array($result)) {
                        echo "<option value=\"".$row['CategoryName']."\">".$row['CategoryName']."</option>";
                    }
                }
            echo "</td>". 
                "</tr>".
                "<tr>".
                "<td colspan=\"2\"><textarea id=\"article_content\" name=\"article_content\" rows=\"15\" cols=\"80\" style=\"width: 80%;\">".$content."</textarea>".
                "<tr>".
                "</table>".
                "<div class=\"RightAlign\">".
                "<input type=\"submit\" name=\"btnSubmit\" value=\"Update Article\" />".
                "<input type=\"hidden\" name=\"srctitle\" value=\"".$title."\" />".
                "<input type=\"hidden\" name=\"action\" value=\"".$action."\" /></div>".
                "</form>";
        break;
        case "New":
            echo "<form name=\"newarticle\" method=\"post\" action=\"articlework.php\">".
                "<table>".
                "<tr>".
                "<td>Article Title<br /><input type=\"text\" name=\"article_title\" style=\"width: 300px;\" /></td>".
                "<td>Category<br />".
                "<select name=\"article_cat\">";    

                $query = "SELECT CategoryName FROM Categories WHERE DeletedYN = 'No'";
                $result = mysql_query($query) or die ("Error in query:<br />".$mysql_error());
                if (mysql_num_rows($result) > 0) {
                    while($row = mysql_fetch_array($result)) {
                        echo "<option value=\"".$row['CategoryName']."\">".$row['CategoryName']."</option>";
                    }
                }
            echo "</td>".
                "</tr>".
                "<tr>".
                "<td colspan=\"2\"><textarea id=\"article_content\" name=\"article_content\" rows=\"15\" cols=\"80\" style=\"width: 80%;\"></textarea></td>".
                "</tr>".
                "</table>".
                "<div class=\"RightAlign\">".
                "<input type=\"submit\" name=\"btnSubmit\" value=\"Create Article\" />".
                "<input type=\"hidden\" name=\"action\" value=\"".$action."\" /></div>".
                "</form>";
        break;
    }
?>

Here's the code that does the work in the database:

<?php
    $action = $_REQUEST["action"];
    $target = $_REQUEST["target"];
    $srctitle = $_POST["srctitle"];
    $title = $_POST["article_title"];
    $cat = $_POST["article_cat"];
    $content = $_POST["article_content"];

    // Set database server access variables:
    $host = "localhost";
    $user = "root";
    $pass = "root";
    $db = "logansarchive";

    // Open connection
    $dbh = new PDO('mysql:host='.$host.';dbname='.$db, $user, $pass);   

    $date = date('Y-m-d H:i:s');
    switch ($action) {
        case "Edit":
            $query = $dbh->prepare("UPDATE Articles ".
                "SET ArticleTitle = :title, Category = :cat, ArticleDate = :date, ArticleContent = :content ".
                "WHERE ArticleTitle = :srctitle");
            $query->bindParam(':title', $title);
            $query->bindParam(':cat', $cat);
            $query->bindParam(':date', $date);
            $query->bindParam(':content', $content);
            $query->bindParam(':srctitle', $srctitle);
            $query->execute();
        break;
        case "New":
            $query = $dbh->prepare("INSERT INTO Articles(Category, ArticleDate, ArticleTitle, ArticleContent) ".
                "VALUES(:cat, :date, :title, :content)");
            $query->bindParam(':cat', $cat);
            $query->bindParam(':date', $date);
            $query->bindParam(':title', $title);
            $query->bindParam(':content', $content);
            $query->execute();
        break;
        case "Delete":
            if ($target != "") {
                $query = $dbh->prepare("UPDATE Articles ".
                    "SET DeletedYN = :del ".
                    "WHERE ArticleTitle = :title");
                $query->bindValue(':del', "Yes");
                $query->bindParam(':title', $target);
                $query->execute();
            }
            else {
                header("Location: index.php?result=failed");
            }
        break;
    }

    header("Location: index.php?result=success");
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不再见 2024-12-08 09:47:56

不,TinyMCE 不使用 进行用户输入。 Tinymce 被初始化为一个 html 元素,该元素在 tinymce 启动时隐藏。 Tinymce 使用 contenteditable iframe 来编辑内容并设置其样式。在特殊事件中,编辑器内容会写回到以前的 html 元素(在许多情况下是文本区域)。 Tinymce 有一个内置的清理功能,它将根据您的tinymce 设置清理您的内容。我想 textarea-tags 会被清理掉。您必须将它们添加到 valid_elements 列表中,也可能添加到 valid_children 列表中。

No, TinyMCE does not use a <textarea></textarea> for user input. Tinymce gets initialized for a html element which gets hidden on tinymce startup. Tinymce uses a contenteditable iframe to edit content and to style it. On special events the editors content gets written back to the former html element (in many cases a textarea). Tinymce has a built-in cleanup functionality which will cleanup your content depending on your tinymce settings. I guess textarea-tags will get cleaned up. You will have to add them to your list of valid_elements and maybe to the list of valid_children.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文