Reputation: 1
i'm a newbie to this community. Seeking your help in doing Mika Tuupola's jEditable. I just want to save the data into the database and show the changes on the page. Below is my code -
<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>
And here is the php code for inserting to database -
<?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);
?>
I'm not able to save it to database. I'm getting an error which says "Undefined index: id in C:\wamp.." and "Undefined index: content in C:\wamp.." Both the "id" and "content" it says as undefined. Please help.
Upvotes: 0
Views: 1880
Reputation: 1989
Jeditable plugin is used to edit the contents inline. based on your code 'OnBlur' event will submit your data to insert.php so in insert.php file you have make to write some code to save it in your database right.
$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
Upvotes: 2