Remove/Update row in database with jquery

On the site users have option to add other users as a friend. Now I want to make option to delete some user from the friend list. The problem is that I don’t know how exactly to do it with jquery part.

This is the button for remove

<a href="#" class="delete" id="'.$row['id'].'"><i class="fa fa-times pull-right"></i></a>

Then this is the jquery part

$(document).ready(function() {

$('.delete').click(function() {
    var parent = $(this).closest('media-heading');
        type: 'get',
        url: 'misc/friendRemove.php', 
        data: 'ajax=1&delete=' + $(this).attr('id'),
        beforeSend: function() {
        success: function() {
            parent.fadeOut(300,function() {

    text: "Are you sure you want to delete?",
    title: "Confirmation required",

    confirmButton: "Yes",
    cancelButton: "No",
    post: true,
    confirmButtonClass: "btn-danger",
    cancelButtonClass: "btn-default",
    dialogClass: "modal-dialog modal-lg"

and the friendRemove.php

    if(isset($_POST['id']) {  

    $friend_id = $_POST['id'];

            $value = $pdo->prepare('UPDATE user_friends SET isDeleted = `1` and isActive = `0` WHERE friend_id= ?');
            $value->bindParam(1, $friend_id, PDO::PARAM_INT);               
            $result = $value->fetch();    


Where I’m wrong?

On Console in the Chrome I get this error so far

friendRemove.php?ajax=1&delete=37 500 (Internal Server Error)

UPDATE: I’m very new into jquery and I used this from one tutorial..

UPDATE: this is the table if it’s matter but I can’t update it even from sql query in the phpmyadmin

  `friend_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `isActive` tinyint(1) NOT NULL DEFAULT '0',
  `isDeleted` tinyint(1) NOT NULL DEFAULT '0',
  `friendsSince` datetime NOT NULL,
   PRIMARY KEY (`friend_id`,`user_id`)

UPDATE: Query should be like this

UPDATE user_friends SET isDeleted = 1, isActive = 0 WHERE friend_id = ?

instead of this

UPDATE user_friends SET isDeleted = 1 AND isActive = 0 WHERE friend_id = ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s