There are may button son php page. I want to submit value of button and the delete record from table using that value. Ajaxz code is
$('#product-table td #delete').live("click", function () {
var doDelete = confirm('Are you sure you want to delete this record?');
deleteLinkObj = $(this);
if (doDelete) {
var id = $(this).attr('accesskey');
$("#deleteid").val(id);
$.ajax({
url: "purchase.php",
data: {deleteid:id},
dataType: 'html',
success: function() {
}
});
}
else { return false; }
});
On PHP I am trying to use value of deleteid but its not coming
PHP code is
if(@$_POST['deleteid']!="")
{
$sql="delete from purchasedetails where purchaseid='".$_POST['deleteid']."'";
if(!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
else
{
$msg="Data is deleted";
}
}
I have tried usinng isset($_POST[‘deleteid’]) then also its showing error
In your ajax call you aren’t setting the request method to
POST, therefore it will default toGET, that is why your post var is never present:As a quick fix for your SQL Injection vulnerability you can cast the id as
int, but you should consider upgrading to PDO or MySQLi because the library you’re using is deprecated.Storing your
purchaseidas the elements accesskey is not the best place, it would be better as adata-myidattribute, so you can access it with$(this).data('myid').