I am currently trying to update a textarea when a user clicks elsewhere. I'm not well-versed in AJAX and Jquery. However, the script doesn't seem to be updating the row in the DB.
Jquery/Text area:
<textarea id="<?php echo $item_id; ?>_textarea"><?php echo $notes; ?></textarea>
<script type="text/javascript">
$('<?php echo $item_id; ?>_textarea').on('blur',function () {
var notesVal = $(this).val(), id = $(this).data('id');
var itemVal = <?php echo $item_id; ?>;
$.ajax({
type: "POST",
url: "updateNotes.php",
data: {notes:notesVal , id:id, itemId:itemVal},
success: function(msg) {
$('#'+id).html(msg);
}
})
});
</script>
updateNotes.php:
<?php
include('db_connect.php');
include('order_functions.php');
$email = $_SESSION['username'];
$cartId = getcartid($mysqli, $email);
$notes = $_POST['notes'];
$itemID = $_POST['itemId'];
$query = "UPDATE `rel` SET `notes` = '$notes' WHERE `cart_id` = '$cartId' && `id_item` = '$itemID'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if(result) {
return "Notes Updated";
} ?>