how to delete from tables with ajax and php with <a href function onclick>. without refresh. I have this code, but it does not work. <script type="text/javascript"> var http = false; if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); }else{ http = new XMLHttpRequest(); } function delete(id) { http.abort(); http.open("POST", "delete.php?id=" +id, true); http.onreadystatechange=function() { if(http.readyState == 27) { alert(http.responseText); } } http.send(null); } </script> <a href="#" onClick="delete(27);">Test</a> HTML: and Delete.php <? $id=$_GET['id']; include ('config.php'); $sql= "DELETE FROM members WHERE id='$id'"; $go= mysql_query($sql) or die (mysql_error()); ?> PHP:
The problem is, you cannot use "delete" as function name. Use another name. And in PHP, for security, you could use addslashes. $id=addslashes($_GET['id']);