dimanche 12 juin 2016

How to delete grand grandparent using jQurery, AJAX and PHP

I am using bootstrap. I want to delete specific row in the database using AJAX and PHP.

I have inserted BOOTSTRAP PANEL inside a .col-md-6. I have inserted delete button inside .panel-footer.

Column id is dynamically generated by PHP and MySQL.

Please help me to delete specific bootstrap column when delete button is pressed.

My HTML code

while($testi = mysql_fetch_array($result))
{ 
    <div class="col-md-6 testiItems" id="'.$testi['testi_id'].'">
                    <div class="panel panel-default">
                <div class="panel-body bg-yellow">
                <img src="http://placehold.it/100x100" class="center-block img-circle img-thumbnail">
                <br>
                <blockquote class="text-black text-justify">
      <p>'.$testi['content'].'</p>
      <footer class="text-black">Someone famous in <cite title="Source Title">Source Title</cite></footer>
    </blockquote>
                </div><!--Testimonials Body-->
                <div class="panel-footer text-center">
                        <div class="btn-group" role="group">
      <button type="button" class="btn btn-danger deleteTesti" id="'.testi['testi_id'].'">Delete</button>
      <button type="button" class="btn btn-primary">Edit</button>
    </div>
                </div>
                   </div><!--Testimonials Panel-->

               </div><!--Testimonials Column-->
}

My jQuery & AJAX

 $('. deleteTesti').click(function(){
            var parent = $(this).parent().parent().parent().attr('id');
            $.ajax({
                type:'POST',
                url:'core/testi-delete.php',
                cache: false,
                data: "delete="+parent,
                success: function(data){

                        alert("Successfully Deleted");

                    }

                });
            });

core/testi-delete.php

<?php
session_start();
include_once 'dbconnect.php';

if(isset($_POST['delete']))
{
$testi_id = $_POST['delete'];
echo 'success';
$qry = "DELETE FROM `testi` WHERE `testi_id` ='$testi_id'";
$result=mysql_query($qry);
}

?>

Aucun commentaire:

Enregistrer un commentaire