2012-03-13 131 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