插入不使用ajax和php的数据库
我有移动div和将position插入数据库的代码,但它不起作用: example.php插入不使用ajax和php的数据库,php,jquery,ajax,mysqli,Php,Jquery,Ajax,Mysqli,我有移动div和将position插入数据库的代码,但它不起作用: 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/j
<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消息。。。但它不是插入或更新mysql数据库。。。。我做错了什么?插件上的限制1是什么?限制是为选择!好吧,我的坏消息是,它正在工作,但当我尝试更新它时,它不是:OSET x='$pos_x'y='$pos_y',其中缺少一个逗号。应该设置x='$pos_x',y='$pos_y'WHERE,并且您必须在WHERE中使用$result的id。谢谢,我真是太蠢了:还有一个问题,当我从db获取位置并将其输出时,我应该为位置做些什么