jQUERY AJAX PHP MYSQL I am geting removed successfuly but nothing removed from database

This is the delete main page The restaurant id in my database is called rId I believe that my error lies in the id part what are my errors? I tried alot of solutions but nothin is working

<!DOCTYPE html>
    <title>Delete restaurant record using jquery ajax</title>

     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap     /3.3.7/css/bootstrap.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="container">
    <h3 class="text-center">PHP mysql confirmation box before delete record using jquery ajax</h3>

    <table class="table table-bordered">
        <th>Restaurant ID</th>
        <th>Restaurant Name</th>
        <th width="100px">Action</th>


$sql = "SELECT * FROM restaurant";
$restaurants = $link->query($sql);

while($restaurant = $restaurants->fetch_assoc()){

    <tr rId="<?php echo $restaurant['rId'] ?>">
        <td><?php echo $restaurant['rname'] ?></td>
        <td><button class="btn btn-danger btn-sm remove">Delete</button></td>

<?php } ?>

</div> <!-- container / end -->
<script type="text/javascript">
        var rId = $(this).parents("tr").attr("rId");
        if(confirm('Are you sure to remove this record ?')) {
                    url: 'http://localhost/PhpProject2/deleter.php',   
                    type: 'GET',
                    data: {rId: rId},
                    error: function() {
                        alert('Something is wrong');
                    success: function(data) {
                        alert("Record removed successfully");  

the file deleting the restaurant

if(isset($_GET['rId'])) {
    $sql = "DELETE FROM restaurant WHERE rId=".$_GET['rId'];
    echo 'Deleted successfully.';

0 Answers