I'm just starting to learn jQuery, php etc. I have a div (scale) with images with two attributes. I want to write those attributes in a database. As they can change (drag & drop) I want to send all img attributes to the database to update every time a new item is dropped into the div. But instead of sending each child of the div only the current (new added) item is send (multiple times).
jQuery
stop: function(event, ui) {
$('#scale').children().each(function(){
var idd = $(this).attr("data-id");
var size2 = parseInt($("#scale > img").length);
var pos = parseInt($(this).index());
var rat = 1.00-(1/size2*pos);
$(this).attr('newRating', rat);
console.log("We send Movie with ID : " + idd + " on Position: " +pos + " to the DB");
$.post("userInfo.php",
{
id:idd,
rating:rat
},
function(data, status){
console.log("Data: " + data + "\nStatus: " + status + " \nof " + $(ui.item).attr('data-id') + " \nwith " + $(ui.item).attr('newRating') );
}
);
});
}
The first console.log gives me the correct ids and ratings, but the data that I get back from the .post() call is wrong.
php
include_once('db.php');
$id = $_POST['id'];
$rating = $_POST['rating'];
if (mysql_query("INSERT INTO MovieRating SET id = '$id', rating ='$rating' ")){
echo "Successfully Inserted";
}
else{
echo "Insertion Failed";
}