I am calling an image with preset dimensions from a mysql database (this part works fine) and then providing the 'resizable' jquery library giving the user the ability to resize an image within a set area without having to press a submit button. The image resizes fine so everything is working there.
Unfortunately I cannot get the new dimensions to save to the database so on refresh the size goes back to the default size I have set, I have been searching for quite a while now on a solution and I am not too strong on ajax and jquery.
Can anyone help?
var startW = ('<?php echo "$w_pos";?>');
var startH = ('<?php echo "$h_pos";?>');
$(document).ready(function() {
$('.resizable').resizable({
start : function(event,ui) {
startW = $(this).outerWidth();
startH = $(this).outerHeight();
},
stop : function(event,ui) {
endW = $(this).outerWidth();
endH = $(this).outerHeight();
alert("Width changed:"+ (startW + ' to ' + endW) + " and Height changed:" + (startH + ' to ' + endH));
$.post('updatedimensions.php', { endW: 'endW', endH: 'endH' });
}
});
});
updatedimensions.php
if(isset($_POST['endW'])){$w_coord=$_POST['endW']}
if(isset($_POST['endH'])){$h_coord=$_POST['endH']}
//Setup Query
$sql = "UPDATE images SET h_pos = '$h_coord', w_pos = '$w_coord' where id = ".$id."";
//Execute Query
mysqli_query($link, $sql) or die("Error updating Coords :".mysqli_error());