我有移动div并将位置插入数据库的代码,但它不起作用:
使用example.php
<html>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$( "#move" ).draggable({
containment: 'parent',
stop: function(event, ui) {
var posx = ui.offset.left;
var posy = ui.offset.top;
$.ajax({
type: "POST",
url: "coor.php",
data: {x: posx, y: posy}
}).done(function( msg ) {
alert( "Data Saved");
});
}
});
});
</script>
</head>
<body>
<div style="width: 400px; height: 500px; margin: 0 auto; border: 1px solid;">
<div id="move" style="width: 100px;">
<p>Move this text with your mouse holding click!!</p>
</div></div>
</body>
</html>
另一个是coor.php
<?php session_start();
include_once('../connect.php');
$probe = $_SESSION['logger'];
$pos_x = $_POST['x'];
$pos_y = $_POST['y'];
$sql = mysqli_query($con, "SELECT * FROM probe WHERE fromid='$probe'");
$result = mysqli_num_rows($sql);
if($result == 1){
$sqliupdate = "UPDATE probe SET x='$pos_x' y='$pos_y' WHERE fromid='$probe' LIMIT 1";
if(mysqli_query($con,$sqliupdate)){
echo "Coords are updated!";
}
}else{
$sqliinsert = "INSERT INTO probe (id, x, y, fromid) VALUES ('','$pos_x','$pos_y','$probe') LIMIT 1";
if(mysqli_query($con,$sqliinsert)){
echo "Coords are inserted!";
}
}
?>
我移动div后我得到了ajax msg ...但是它没有插入或更新mysql数据库....我做错了什么?