Using php + jquery/ajax + mysql
Everything works fine when I try to insert one record
My steps:
- I insert a row in a blank mysql table by ajax. (Ok)
- I check that the new and the only one row is in there (ok)
- I try to delete that (new and the only one) row by ajax (ok)
- console.log shows me: mysqli_affected_rows 1 row affected (ok)
- console.log and mysql reports me that the row was deleted correctly. No errors or warnings (ok)
- When I take a look to the table, the new and the only one row is still there! (fail)
Just when I add one more row with the same procedure I'm able to delete the 'old and not the only one' row by ajax and then it happens the same with the new last row.
The query
$sql=mysqli_query($connmysql,"DELETE from locations where iddata='97' and location='01-N-D-34' and items='48'")or die(mysqli_error($connmysql));
echo mysqli_affected_rows($connmysql);
$connmysql->close();
This is the ajax(simplified but tested)
$.ajax({
type: "POST",
url: "delete.php",
dataType: "text",
success: function(response) {
console.log(response);
},
error: function(xhr,textStatus,err) {
console.log("readyState: " + xhr.readyState);
console.log("responseText: "+ xhr.responseText);
console.log("status: " + xhr.status);
console.log("text status: " + textStatus);
console.log("error: " + err);
}
});
EDITED
Sorry, it was my fault.
It was something related with jquery and a class name in the wrong place . I was triggering an 'insert' and a 'delete' every time I was clicking the 'delete' button. Basically, I was deleting a record and inserting it again with the same content. Thanks anyway for your support.