使用PHP和MySql,我试图在这里实现这个相当时髦的就地编辑器:
教程: http://www.davehauenstein.com/code/jquery-edit-in-place/
js文件: http://davehauenstein.com/code/scripts/jquery.inplace.min.js
好的,发生了什么,
问题:只有在我手动刷新页面后,才会在元素中加载新文本。而不是在没有刷新的情况下加载元素。
具有就地编辑的元素:
<div class="editme1"><?php
$content = $_GET['update_value'];
// i added this to try and get the updated value but im
// not really sure, just a guess. i have also used $_POST
// in an attempt to catch it....but i feel stupid even
// saying that..lol
if(!empty($content)) { echo "$content"; } else
{ echo "$row[profilevalue_8]"; }
?></div>
更新数据库的文件(update.php):
<?php include('includes/config.php');
include('includes/functions.php');
$name = $_POST[update_value];
$update = mysql_query("UPDATE profilevalues SET profilevalue_8 = '".$name."'
WHERE profilevalue_user_id = '".uid()."'") or die(mysql_error());
?>
javascript
<script type="text/javascript">
$(document).ready(function(){
$(".editme1").editInPlace({
url: "http://www.mysite.com/update.php",
params: "ajax=yes",
});
</script>
我想问题是,我似乎无法按预期反映元素的变化。
如果有任何帮助,我将非常感激。
由于
答案 0 :(得分:1)
你忘记了update.php
:)中的每一个In in Place编辑器对更新文件发出了一个AJAX请求,然后在编辑后的元素中添加了update.php
中带有该请求的内容。< / p>
所以你的update.php需要像这样
<?php include('includes/config.php');
include('includes/functions.php');
$name = $_POST[update_value];
$update = mysql_query("UPDATE profilevalues SET profilevalue_8 = '".$name."'
WHERE profilevalue_user_id = '".uid()."'") or die(mysql_error());
echo $_POST['update_value']; //add this to your file and it should be working now
?>
答案 1 :(得分:0)
为了补充Bogdan Constantinescu所说的内容,我认为值得指出的是,为了防止人们输入令人讨厌的数据,你应该真的
htmlspecialchars()
。这有助于防止XSS攻击。mysql_real_escape_string()
。这将保护您免受SQL注入攻击。