2012-03-13 130 views
0

我是这个社区的新手。在Mika Tuupola的jEditable寻求你的帮助。 我只想将数据保存到数据库中并显示页面上的更改。下面是我的代码 -jEditable - 保存到数据库

<head> 
<script src="js/jquery-1.7.1.js" type="text/javascript" charset="utf-8"></script> 
<script src="js/jquery.jeditable.js" type="text/javascript" charset="utf-8"></script> 
<script type="text/javascript" charset="utf-8"> 

$(document).ready(function() { 
$("#editab").editable("insert.php", { 
id : 1, 
content : 'editab', 
indicator : "<img src='img/indicator.gif'>", 
tooltip : "Doubleclick to edit...", 
event  : "click", 
height : 'auto', 
onblur : 'submit', 
}); 
}); 

</script> 
</head> 

<body> 
<div style="width:640px" class="editable" id="editab">sdfsdf</div> 
</body> 
</html> 

,这里是插入到数据库中的PHP代码 -

<?php 
$con = mysql_connect("localhost","root",""); 
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); 
?> 

我不能将它保存到数据库中。我收到一个错误,里面写着“未定义的索引:ID在C:\ wamp ..”和“未定义的索引:C:\ wamp中的内容..”。 它表示未定义的“id”和“content”。请帮忙。

回答

2

Jeditable插件用于内联编辑内容。根据你的代码,'OnBlur'事件会将你的数据提交给insert.php,因此你可以在insert.php文件中编写一些代码将它保存到数据库中。

$name = $_REQUEST['id']; // get from request and store your data in variable 

$query="insert into data SET 
        name = '".$name."'; //write db query to save it in db 

    mysql_query($query) or die(mysql_error()); //execute your query 
    echo 'ok'; //for acknowledgement