How to Delete record using PHP Ajax

index.php

 
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
 
<?php
 
    $connection = mysqli_connect("localhost","root","","db_2018") or die(mysqli_error());
 
    $ReadSql = "SELECT * FROM `crud`";
    $res = mysqli_query($connection, $ReadSql);
 ?>
 
 <table>
    <tr>
        <th>name</th>
        <th>Last Name</th>
        <th>email id</th>
        <th>gender</th>
        <th>age</th>
        <th>Action</th>
    </tr>
 
    <?php while($fetch = mysqli_fetch_array($res)) {
 
        extract($fetch);
 
 
 
 
?>
 
<tr>
    <td><?php echo $fetch['first_name']; ?></td>
    <td><?php echo $fetch['last_name']; ?></td>
    <td><?php echo $fetch['email_id']; ?></td>
    <td><?php echo $fetch['gender']; ?></td>
    <td><?php echo $fetch['age']; ?></td>
    <!-- <input type="hidden" name="" id="v" value="<?php //echo $fetch['id']; ?> "> -->
    <td><a href="javascript:;" class='delete' id='<?php echo $fetch['id']; ?>'>Delete</a></td>
</tr>
 
        <?php } ?>
 </table>
 
 
 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
 
 
        $(".delete").click(function (){
 
            var id= $(this).attr("id");
 
            $.get("delete.php",{id:id},function(data){
                     
                    alert('deleted successfully');
 
                });
 
        });
 
    });
     
 
 
 
</script>
</body>
</html>
 
 

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<?php 

    $connection = mysqli_connect("localhost","root","","db_2018") or die(mysqli_error());

    $ReadSql = "SELECT * FROM `crud`";
    $res = mysqli_query($connection, $ReadSql);
 ?>

 <table>
    <tr>
        <th>name</th>
        <th>Last Name</th>
        <th>email id</th>
        <th>gender</th>
        <th>age</th>
        <th>Action</th>
    </tr>

    <?php while($fetch = mysqli_fetch_array($res)) {

        extract($fetch);




?>

<tr>
    <td><?php echo $fetch['first_name']; ?></td>
    <td><?php echo $fetch['last_name']; ?></td>
    <td><?php echo $fetch['email_id']; ?></td>
    <td><?php echo $fetch['gender']; ?></td>
    <td><?php echo $fetch['age']; ?></td>
    <!-- <input type="hidden" name="" id="v" value="<?php //echo $fetch['id']; ?> "> -->
    <td><a href="javascript:;" class='delete' id='<?php echo $fetch['id']; ?>'>Delete</a></td>
</tr>

        <?php } ?>
 </table>



<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){


        $(".delete").click(function (){

            var id= $(this).attr("id");

            $.get("delete.php",{id:id},function(data){
                    
                    alert('deleted successfully');

                });

        });

    });
    



</script>
</body>
</html>

delete.php

 
01
02
03
04
05
06
07
08
09
10
11
<?php
       
$con = mysqli_connect("localhost","root","","db_2018");
     
        $id=$_GET['id'];
     
    $del_query=mysqli_query($con,"delete from crud where id='$id'") or die(mysqli_error($con));
     
 
 
?>
 
 

<?php
      
$con = mysqli_connect("localhost","root","","db_2018");
    
        $id=$_GET['id'];
    
    $del_query=mysqli_query($con,"delete from crud where id='$id'") or die(mysqli_error($con)); 
    


?>


Comments

  1. Your blog is so nice, and the article is very good it helps to so many people.
    PHP Training in Hyderabad

    ReplyDelete
  2. Want to get ranked your business on the top? Contact Shahni Digital Media, one of the fastest growing Digital Marketing Company in India. We provide web development solution, orm, ppc, smm, sem etc.
    Digital Marketing Company Bhopal
    Website Designing Company Bhopal
    SEO Company in Bhopal
    ORM Company India

    ReplyDelete
  3. I need to to thank you for this excellent read!! I absolutely loved every bit of it. I have you saved as a favorite to look at new things you post…
    UI Development Training in Bangalore
    Reactjs Training in Bangalore

    ReplyDelete
  4. I undoubtedly welcome the way wherein you continue posting such shocking and huge articles and continue empowering your blog with most recent bearing. Keep up this goliath work. Keep framing. Dedicated hosting reviews

    ReplyDelete
  5. Great Article ,I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    DevOps Training in Chennai

    DevOps Online Training in Chennai

    DevOps Training in Bangalore

    DevOps Training in Hyderabad

    DevOps Training in Coimbatore

    DevOps Training

    DevOps Online Training

    ReplyDelete
  6. I need to to thank you for this excellent read!! I absolutely loved every bit of it. I have you saved as a favorite to look at new things you post…
    acte reviews

    acte velachery reviews

    acte tambaram reviews

    acte anna nagar reviews

    acte porur reviews

    acte omr reviews

    acte chennai reviews

    acte student reviews

    ReplyDelete
  7. JavaScript will remain a very popular language for years to come. it would be suicide to your career as a web developer not to know it. It's foreseeable that JavaScript will not only conserve but extend its hold of the overall software industry during the coming years.keep up!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training


    ReplyDelete
  8. Si Contact Form Plugin using for captcha to setup contact form in get it proper way it make properly

    ReplyDelete
  9. Woocommerce Floating Cart setup in woocommerce side cart in your ecommerce website

    ReplyDelete
  10. fast secure contact form for setup contact form with captcha and secure in your wordpress site

    ReplyDelete
  11. Calculated Fields Form WordPress Plugin In Calculate Field to each other we can use wordpress plugin for calculation. let We explain you how to make Calculation Field in wordpress.

    ReplyDelete
  12. Calculated Fields Form WordPress Plugin In Calculate Field to each other we can use wordpress plugin for calculation. let We explain you how to make Calculation Field in wordpress.

    ReplyDelete
  13. Thank you for discussing this very useful article. I heard something new from you. Keep blogging. php training in jalandhar

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Thanks for sharing such types of articles on your website. I have read the complete article that you have explained properly. Thanks a lot for this article. For any kind of website development in the PHP Language,
    visit our website

    ReplyDelete
  16. Thanks for providing awesome lecture about PHP. I hope you will keep it up.

    ReplyDelete
  17. It is nice post and I found some interesting information on this blog, keep it up. Thanks for sharing. . .
    Hire PHP framework in India

    ReplyDelete

Post a Comment

Popular posts from this blog

How to seperate character from string in php

Uploads Only 10 files in month step by step