Hi,
I have a ‘to do’ item in a page that has an ID attached to it. These items are stored in a database. When clicked I want to reverse the ‘state’ of the item (active to complete or complete to active) by updating the database using jquery & PHP.
I think I almost have it. As all the values are collected ok and if I change the the page that writes to the database to GET and pass the data through the URL it updates the database fine.
Where am I going wrong?
/*////// My items HTML /////////*/
<li id="todosArray_<?php echo $row['todo_id']; ?>" class="todo <?php echo $row['statename']; ?>"><a href"" id="<?php echo $row['todo_id']; ?>"><?php echo $row['text'] " - " . $row['todo_id']; ?></a></li>
/*////// my JQUERY function
$('.todo a').click(function() {
// get toto id
var todoID = $(this).attr("id");
alert(todoID);
if($(this).parent().hasClass('active')){
alert("active");
var todoState = '1';
}
if($(this).parent().hasClass('complete')){
alert("complete");
var todoState = '2';
}
$.ajax({
type: "POST",
url: "functions/todos-state.php",
data: "todoID="+todoID+"&todoState="+todoState,
success:function(data_response){
alert(data_response);
alert(todoID);
alert(todoState);
}
});
return false;
});
/*///// my todos-state.php
$todoID = htmlspecialchars(trim($_POST["todoID"]));
$todoState = htmlspecialchars(trim($_POST["todoState"]));
$query = "UPDATE todos SET state_id = " . $todoState . " WHERE id = " . $todoID . "";
mysql_query($query) or die('Error, insert query failed');