开发者

TinyMCE and php problems

开发者 https://www.devze.com 2023-03-30 18:46 出处:网络
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\".

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%;开发者_StackOverflow\"></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");
?>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消