【问题标题】:YUI editor content save in database PHPYUI 编辑器内容保存在数据库 PHP
【发布时间】:2012-02-14 11:21:05
【问题描述】:

我正在使用 YUI 编辑器。我试图获取textarea 值并将其保存在数据库中,但我无法这样做。这是我的代码。

@$titleidz=$_POST['title'];
@$contentidz=$_POST['editor'];
if($titleidz && $contentidz)
{
include_once('../config/config.php');
$q= "insert  into tbl_page(title, content) values('$titleidz', '$contentidz')" ;
$result=mysql_query($q) or die(mysql_error());    
<form action="" name="form" method="post">
<table style="table-layout: fixed;width:100%">
<tr><input class="input_text" type="text" size="50" name="title" placeholder="Enter Your Title" id="title"></td><td><span style="color:red" id="errTitle"></span></td></tr>
<tr><td><textarea id="editor" name="editor" rows="20" cols="75">fffffffff</textarea></td></tr>
<tr><td colspan=2 align="middle"><input type="submit"></td></tr>
</table>
</form>
<script>

(function() {
var Dom = YAHOO.util.Dom,
    Event = YAHOO.util.Event;

var myConfig = {
    height: '300px',
    width: '990px',
    animate: true,
    dompath: true,
    focusAtStart: true
};

var myEditor = new YAHOO.widget.Editor('editor', myConfig);
myEditor.render();

})();

【问题讨论】:

  • 什么问题,什么不起作用?
  • 旁注:您显示的代码易受SQL injection 的攻击。使用正确的库清理方法(例如经典 mysql 库的mysql_real_escape_string()),或切换到 PDO 和准备好的语句。
  • 这不是普通的textarea,我用的是yui富文本编辑器
  • 我明白这一点。不知道你的意思是什么?它仍然容易受到 SQL 注入的影响
  • 再次。什么问题,什么不起作用?

标签: php yui rich-text-editor


【解决方案1】:

您需要在提交表单之前为 yui 编辑器调用saveHTML() 方法以获取值然后保存:

YAHOO.util.Event.on('somebutton', 'click', function() {
    //Put the HTML back into the text area
    myEditor.saveHTML();

    //The var html will now have the contents of the textarea
    var html = myEditor.get('editor').value;
});

然后将变量html的内容保存在您的数据库中

更多详情请参阅here

【讨论】:

    【解决方案2】:

    在没有 YUI 编辑器的情况下它是否适用于输入字段?

    尝试在代码开头添加 var_dump($_POST)。这样,您将看到发布到服务器的内容。这是基本的调试:)

    【讨论】:

    • 我检查了var_dump($_POST),但我没有收到我在 textarea 中写的文字
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多