好吧,昨天我終於得到了TinyMCE在我的網站上工作。 我還下載了一個插件,它提供了代碼突出顯示,但插件似乎導致了一些「混淆」。TinyMCE和php問題
正如我們使用它知道的那樣,TinyMCE使用<textarea></textarea>
作爲用戶輸入。那麼,我爲它下載的代碼高亮插件也是如此。我從來沒有使用過textarea,但是看起來你不能在另一箇中嵌套。 如果我通過插件向我的文本添加代碼示例,TinyMCE似乎認爲文章結束於插件寫入的textarea的結束標記,而不是文章底部的標記。 任何人都可以推薦更好的插件嗎?
至於PHP很好,這讓我不知所措。我的代碼昨天立即運行,但一旦我今天嘗試使用它,它就會超時。我試圖做的是在TinyMCE中加載的記錄上的mysql更新。 我知道這不是mysql導致的問題,因爲我仍然可以用phpmyadmin登錄並在那裏的任何數據庫上工作。 我不知道從哪裏開始故障查找,如果任何人都可以提供指導,那將不勝感激。
爲了記錄在案,這裏是當我嘗試提交我的形式,我發現了錯誤,並且PHP代碼背後的背後:
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
代碼動態地根據其行動產生一種形式被用戶選中(創建新文章或編輯現有文章)。
<?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");
?>
在我的tinymce選項中,我有'extended_valid_elements:「textarea [name | class | cols | rows]」'錯誤,這樣可以解決它,但不幸的是,更新命令仍然超時,所以我不能檢查任何方式。 – Ortund
你可以記錄試圖更新數據庫時執行什麼查詢嗎?更多的調試輸出可以告訴你你的php腳本確實掛在哪裏 – Thariama