javascript - delete data with ajax -
i unable delete records database, fetching code working delete code not working. please help me out.. in advance
code fetch info ajax
$(document).ready(function(){ done(); }); function done(){ settimeout(function(){ updates(); done(); }, 200); } function updates(){ $.getjson("fetch.php",function(data){ $("table").empty(); $("table").append("<tr><td>name</td><td>date</td><td>delete</td></tr>"); $.each(data.result, function(){ $("table").append("<tr><td>"+this['text']+"</td><td>"+this['date']+"</td><td><a id='del' href='"+this['id']+"'>del</a></td></tr>"); }); }); }
code delete info ajax
$(function() { $("#del").click(function(){ var element = $(this); var id = element.attr("id"); var datastring = 'id=' + id; if(confirm("sure want delete comment?")) { $.ajax({ type: "get", url: "del.php", data: datastring, success: function(){ } }); } homecoming false; }); });
php code del.php
$last_page_id = $_request['d_i_d']; $sql = mysql_query("delete time id = '{$last_page_id}'"); if(!$sql){ echo mysql_error(); }else{ header('location: index.php'); }
ajax data: datastring = 'id=' + id;
calling in php: $last_page_id = $_request['d_i_d'];
you can id $_request['id']
please note mysql_ deprecated: why shouldn't utilize mysql_* functions in php?
and code open sql injection: http://en.wikipedia.org/wiki/sql_injection
javascript php jquery ajax
No comments:
Post a Comment