How to delete a record from MySQL database using AJAX and PHP in Codeigniter

SholleyonlineJava

I want to delete records from a MySQL database table using AJAX. I have done it with PHP and work fine. But I've not been able to get it through with AJAX.

AJAX

$(document).ready(function() {
    $(".confirm").click(function() {
        var bid = $(this).closest("div.box2").find('input[name="dbid"]').val();
        var dataString = 'id=' + bid;
        $.ajax({
            type: "POST",
            url: "<?php echo site_url('user/delete_article')?>",
            data: dataString,
            cache: false,
            success: function() {

                $.alert('Confirmed!');
            }
        });
    });
}); 

PHP

public function delete_article($id){
  $data['success']='';
  $data['error']='';
  include_once ('query/user_query.php');  
  $this->db->where('bid', $id);
  $data['countEarticle'] = $this->db->count_all_results('blog');
  if($data['countEarticle'] >= 1){

      $this->db->where('bid',$id);
      $this->db->delete('blog');

  }
  if($data['countEarticle'] <= 0){

  }          
}

HTML

<div class="box-footer box-comments box2" style="display: block;">
    <input type="hidden" name="dbid" value="<?php echo $draftfull['bid']?>">
    <p>
        <btn class="btn btn-azure btn-sm confirm"><i class="fa fa-trash-o"></i>Delete Article</btn>
    </p>
</div>

I need your help. What am I doing wrong?

Parvej Alam

try this code:-

public function delete_article(){
    $id=$this->input->post('bid');
    $data['success']='';
    $data['error']='';
    include_once ('query/user_query.php');

    $this->db->where('bid', $id);
    $data['countEarticle'] = $this->db->count_all_results('blog');
    if($data['countEarticle'] >= 1){

        $this->db->where('bid',$id);
        $this->db->delete('blog');

    }
    if($data['countEarticle'] <= 0){

    }          
   }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Delete record from database using AJAX

Delete record by using ajax from database EntityFramework

How to delete a specific record from database mysql by using Volley

Delete image from database using ajax and php

How to delete mysql database data from table, using php

cant delete record from database using $.ajax() function

Cannot delete record in CodeIgniter using AJAX

How to delete from my database in PHP/mysql?

delete record from table using codeigniter

how to auto run a php script and delete a record from database

How to remove HTML row and delete entry from MySQL database using AJAX?

How to get the last record from database using ajax

How to get data from database using AJAX in CodeIgniter?

PHP Ajax delete a record from table

how to get one record from a mysql database with php

How can i delete data from database with foreign key constraint in mysql using php pdo

Cannot delete record from mysql with this statement in php

how to delete duplicates record from a mongodb database

How to delete image from directory and database in codeigniter

How to delete multiple rows from MYSQL database with PHP no frameworks

Using Ajax, JavaScript, PHP to delete database entries

Using jQuery, AJAX, PHP to delete row in database

Insert json in mysql database using php in codeigniter

How to delete millions of record from mysql table

Fetch the record for database using Codeigniter

How to delete record from table using Angular http.delete with PHP backend?

Fetch single record from database and display in text box using Codeigniter

Data has been deleted from database but table row not removed and total record not reduced in php using ajax

I am trying to delete a record in the database using mysql javascript API

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  7. 7

    Do Idle Snowflake Connections Use Cloud Services Credits?

  8. 8

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  9. 9

    Binding element 'string' implicitly has an 'any' type

  10. 10

    BigQuery - concatenate ignoring NULL

  11. 11

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  12. 12

    In Skype, how to block "User requests your details"?

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Pandas - check if dataframe has negative value in any column

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Generate random UUIDv4 with Elm

  17. 17

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  18. 18

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  19. 19

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  20. 20

    EXCEL: Find sum of values in one column with criteria from other column

  21. 21

    How to use merge windows unallocated space into Ubuntu using GParted?

HotTag

Archive