Post and query mysql database [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this questionon one page I have t开发者_开发问答he following code:
$("#photolist").dragsort({
dragBetween: true,
dragEnd: saveOrder,
placeHolderTemplate: "<li class='placeHolder'><div></div></li>"
});
function saveOrder() {
var data = $("#photolist li").map(function() {
return $(this).children().find('img').attr('id');
}).get();
$("input[name=SortOrder]").val(data.join("|"));
var map = $('input[name=SortOrder]').val();
$.ajax({
type: 'POST',
url: 'updatephotoposition.php',
data: "map=" + map,
success: function(){
alert("success");
}
});
};
It is definitely firing because the alert is functioning.
on my page updatephotoposition.php I use the following code:
<?php
include '../dbconnect.php';
$map = explode('|', $_POST['map']);
foreach ($map as $position => $ID)
{
$query = "UPDATE Photos SET Position = '$position' WHERE PhotoID = '$ID';";
$result = mysql_query($query) or die(mysql_error());
}
?>
But my database isn't getting updated, can anyone see a problem with this set up?
Post data sent: 82|83|84|85|86|81|87|88|89
EDIT: This has suddenly started working
This could be related to your mysql. Your field 'Position' could be conflicting with the reserved function name POSITION (http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_position).
Try popping some accented quotes around your field name to escape it:
`Position`
精彩评论