Note that there are some explanatory texts on larger screens.

plurals
  1. POdelete record in a table using jquery ajax
    text
    copied!<p>I am learning j query Ajax events.I have inserted and displayed records in php using j query Ajax but I am not able to delete record I have written code but its not working and I don't want table to load again.Please help</p> <p>TableName : login</p> <p>Column: id,username,message</p> <p>comment.php</p> <pre><code> &lt;script type="text/javascript"&gt; $(document).ready(function(e) { function showComment(){ $.ajax({ type:"post", url:"process2.php", data:"action=showcomment", success:function(data){ $("#flash").html(data); } }); } showComment(); //Insert records $("#Submit").click(function(){ if($(":text").val().length==0) { // $(this).next().html("Field needs filling"); $(":text").after('&lt;span class="errorkeyup"&gt;Field cannot be empty&lt;/span&gt;'); //return false; success = false; } else { var name=$("#name").val(); var message=$("#message").val(); $.ajax({ type:"post", url:"process2.php", data:"name="+name+"&amp;message="+message+"&amp;action=addcomment", success:function(data){ showComment(); } }); } }); $('.delete').click(function(e){ e.stopPropagation(); var deleteID = $(this).attr('name'); var row = deleteID; $.ajax({ type: "POST", url: "delete.php?deleteID=" + deleteID, data: "deleteID="+ deleteID, success: function(result){ $('#row'+row).fadeOut('fast'); } }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="post" name="form" action=""&gt; &lt;div id="content"&gt; Name : &lt;input type="text" name="name" id="name"/&gt; &lt;/br&gt; Message : &lt;input type="text" name="message" id="message" /&gt; &lt;/br&gt; &lt;/div&gt; &lt;input type="button" value="Submit" id="Submit"&gt; &lt;/form&gt; &lt;/div&gt; &lt;div id="flash"&gt;&lt;/div&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p>process.php</p> <pre><code> &lt;?php mysql_connect("localhost","root","dot1235"); mysql_select_db("chitra"); $action=$_POST["action"]; if($action=="showcomment"){ $show=mysql_query("Select * from login order by id ASC"); echo "&lt;table border=1 id=t1&gt;"; echo "&lt;tr&gt;"; echo "&lt;td&gt;SrNo.&lt;/td&gt;"; echo "&lt;td&gt;Name&lt;/td&gt;"; echo "&lt;td&gt;Message&lt;/td&gt;"; echo "&lt;td&gt;Delete&lt;/td&gt;"; echo "&lt;/tr&gt;"; $i=1; while($row=mysql_fetch_array($show)){ //echo "&lt;li&gt;&lt;b&gt;$row[name]&lt;/b&gt; : $row[message]&lt;/li&gt;"; echo "&lt;tr&gt;"; echo"&lt;td&gt;".$i."&lt;/td&gt;"; echo "&lt;td&gt;" .$row['username'] ."&lt;/td&gt;"; echo "&lt;td&gt;" .$row['message'] ."&lt;/td&gt;"; echo "&lt;td&gt;&lt;a href='javascript:void(0)'&gt;&lt;img src=delete.png class=delete name=".$row[id]."&lt;/a&gt;&lt;/td&gt;" ; echo "&lt;/tr&gt;"; $i++; } echo"&lt;/table&gt;"; } else if($action=="addcomment"){ $name=$_POST["name"]; $message=$_POST["message"]; $query=mysql_query("insert into login(username,message) values('$name','$message') "); if($query){ echo "Your comment has been sent"; } else{ echo "Error in sending your comment"; } } ?&gt; </code></pre> <p>delete.php</p> <pre><code>&lt;?php include("connection.php"); if(isset($_POST['id'])) { $id = $_POST['id']; $id = mysql_escape_String($id); $delquery=mysql_query("delete from login where id=$id") or die(mysql_error()); //echo "Record deleted"; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload