I'm a newbie in AJAX.
I looked for the solution in Google, but I didn't find a working solution.
So, I want to send data from a jquery's draggable div to sql via php.
index.html :
<html>
[...]
<body>
<myDiv>bla bla</div>
<script>
$( "myDiv" ).draggable({ stop: function() {
var position = $(this).position();
var xPos = $(this).css('left');
$.ajax({
type: "post",
url: "update.php",
data: xPos,
cache: false,
}
}
});
</script>
</body>
</html>
update.php :
<?php
require("db.php");
$xpos = $_POST['xPos'];
mysql_query("UPDATE item SET pos_x = '" . $xpos . "' WHERE ID = '". $post_ID."'");
mysql_query($query) or die('Error, insert query failed');
}
?>
db.php :
<?php
$dbhost = "**";
$dbuser = "**";
$dbpass = "**";
$dbname = "**";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Error connecting to mysql");
mysql_select_db($dbname);
?>
Could someone tell me where I'm wrong?
update.phpcontains a syntax error; why is}there? You also have no SQL injection prevention whatsoever; why not?magic_quotes_gpson.);after the braces on thecache: falseline in your js. And where is$post_IDdefined in your php?