I have two buttons in a form. The update button updates the data and works fine. I am trying to implement a delete button that will delete the record based on which ever number is echoed in the button attribute value. Right now it is not doing anything.
<form id="update_form" action="" method="post">
<button id="update" type="submit" value="update">Update</button>
<button id="unprocess" type="button" value="'.$order_no.'">DEL</button>
</form>
My Jquery
$("#unprocess").click(function (e) {
e.preventDefault();
$.ajax({
url: 'unprocess.php',
data: $(this).val(value),
type: 'POST',
success: function (data) {
$(".error").css('display','none');
$(".success").css('display','block');
$('#search').focus();
},
error: function(data){
$(".success").css('display','none');
$(".error").css('display','block');
}
});
});
My Query:
$order = $_POST['value'];
$sql = "DELETE FROM table WHERE ord_no = $order";
$query = odbc_exec($conn, $sql);
I made the changes on line data:$(this).val(value), now the browser is at least capturing the value of the button, but it is not being passed to the query. any ideas
Try data: { value: $(this).val() }
instead of data: $(this).serialize("value")
To solve your problem:
(1) As a test, echo back the value from PHP to make sure you have the right thing.
PHP side
<?php
$v = $_POST["value"];
die ($v);
AJAX success function:
alert(data);
return false;
Then, (2) Create a standalone version of your PHP file with hard-coded values. See if it inserts into the database.
You will quickly find your problem.
$("#unprocess").click(function (e) {
e.preventDefault();
$.ajax({
url: 'unprocess.php',
data: {order_no:this.value},
type: 'POST',
success: function (data) {
$(".error").css('display','none');
$(".success").css('display','block');
$('#search').focus();
},
error: function(data){
$(".success").css('display','none');
$(".error").css('display','block');
}
});
});