gpt4 book ai didi

php - JEdi​​table 未保存在 Mysql 中

转载 作者:行者123 更新时间:2023-11-29 14:38:44 24 4
gpt4 key购买 nike

我不知道这是否正确 - 我只是按照 jeditable 网站上的示例进行操作,但我似乎无法让这个简单的代码正常工作。我只想将数据保存到数据库中并仍然在页面上显示更改。

下面是我的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" debug="true">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Jeditable WYSIWYG Custom Input Demo</title>
<meta name="generator" content="Mephisto" />
<link href="http://www.appelsiini.net/stylesheets/main2.css" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/atom+xml" href="http://feeds.feedburner.com/tuupola" title="Atom feed" />
<script src="/mint/?js" type="text/javascript"></script>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js""

type="text/javascript" charset="utf-8"></script>
<script src="http://www.appelsiini.net/projects/jeditable/wysiwyg/wysiwyg/jquery.wysiwyg.js" type="text/javascript"></script>
<link rel="stylesheet" href="http://www.appelsiini.net/projects/jeditable/wysiwyg/wysiwyg/jquery.wysiwyg.css" type="text/css" media="screen" charset="utf-8">

<script src="http://www.appelsiini.net/projects/jeditable/jquery.jeditable.js" type="text/javascript" charset="utf-8"></script>
<script src="http://www.appelsiini.net/projects/jeditable/wysiwyg/jquery.jeditable.wysiwyg.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$(function() {

/* Fix FireBug */
/*
if ($.browser.mozilla) {
window.loadFirebugConsole();
};
*/
/* Handle links inside editable area. */
$('.editable > a').bind('click', function() {
$(this).parent().trigger('click');
return false;
});

$('#wysiwyg_2').editable('test-jedit.php',

{
id : 1,
content : 'wysiwyg_2',
indicator : '<img src="../img/indicator.gif">',
type : 'POST',
type : 'wysiwyg',
width : 640,
height : 'auto',
onblur : 'ignore',
submit : 'OK',
cancel : 'Cancel',
wysiwyg : { controls : { separator04 : { visible : true },
insertOrderedList : { visible : true },
insertUnorderedList : { visible : true }
}
}
});

});
</script>

<style type="text/css">
#sidebar {
width: 0px;
}

#content {
width: 770px;
}
</style>
</head>
<body>
<div id="wrap">
<div id="header">
<p>
<h1>Jeditable</h1><br />
<small>Edit in place plugin for jQuery.</small>
<ul id="nav">
<li id="first"><a href="/" class="active">weblog</a></li>
<li><a href="/projects" class="last">projects</a></li>
</ul>
</p>
</div>
<div id="content">
<div class="entry">
<p>You might also want to check <a href="../custom.html">other custom inputs demo</a>.

<h2>Extra settings</h2>
<div style="width: 640px" class="editable" id="wysiwyg_2"><img

src="%5C%22http://%5C%22"><span style="\&quot;font-weight:" bold;\"="">gdgfd<span style="font-style: italic;">
gfd</span><big><br>sdfsdf<br>sdfsdf<br><br></big></span></div>
</div>

<div id="sidebar">
</div>
<div id="footer">
</div>
</body>
</html>

这是 PHP 代码:

<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$id = $_POST['id'];
$content = $_POST['content'];
mysql_query("INSERT INTO editable (id, content)
VALUES ('$id', '$content')");

echo $content;
mysql_close($con);
?>

最佳答案

首先要说的是,请阅读 php.net page about SQL Injection

针对您的问题...

我想我可能发现了一个问题...您的 JavaScript 正在 DOM 准备好之前执行...将您的 javascript 代码(全部)包含在以下 block 中:

$(document).ready(function() {
// your code here
});

这意味着函数中的代码只有在整个页面加载完毕后才会执行...在未加载的 DOM 元素上调用函数会导致问题... further reading on ready() ...

查看代码,我看不出明显的问题 - 但是,您可以执行一些基本操作来调试此问题...首先检查(使用 firebug 之类的东西)AJAX 请求实际上正在发送...

其次您可以检查 PHP MySQL 代码是否正常工作...

$result = mysql_query($query); // execute your query

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}

// if you get to here the query worked fine ...

更新

我使用了你的代码并创建了一个 jsfiddle

需要进行一些小的更改才能使其正常工作:

<div style="width: 640px" class="editable" id="wysiwyg_2">
<img src="%5C%22http://%5C%22"><span style="\&quot;font-weight:" bold;\"="">gdgfd
<span style="font-style: italic;"> gfd</span>
<big><br>sdfsdf<br>sdfsdf<br><br></big></span></div>

应该是:

<div style="width: 640px" class="editable" id="wysiwyg_2"><span style="font-weight: bold;">gdgfd<span style="font-style: italic;">
gfd</span><br>sdfsdf<br>sdfsdf<br><br></span></div>

我已经删除了奇怪的字符!

更新2

当按下“确定”按钮时,将调用 PHP - 它会发布以下数据:

1:wysiwyg_2
value:<span style="font-weight: bold;">gdgfd<span style="font-style: italic;">
gfd</span><big><br>sdfsdf<br>sdfsdf<br><br></big></span>

因此,在 PHP 中,您需要将 $_POST['content'] 更改为 $_POST['value']

关于php - JEdi​​table 未保存在 Mysql 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8444481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com