0

Could anyone help me?I have the code below to insert,edit and delete data in database from an excisting table.Data are added in database but not edit and delete. What should i do?

 jQueryOb(function new_dialog() {

    var new_dialog = function (type, row) {
        var dlg = jQueryOb("#dialog-form").clone();
        var fname = dlg.find(("#fn1")),
            lname = dlg.find(("#fn2")),
            email = dlg.find(("#fn3")),

        type = type || 'Create';
        var config = {
            autoOpen: true,
            height: 300,
            width: 350,
            modal: true
      },
            buttons: {
              "Create an account": save_data,
                    "Cancel": function () {
                    dlg.dialog("close");

                }
            },
            close: function () {
                dlg.remove();
            }
        };
        if (type === 'Edit') {
            config.title = "Edit User";
            get_data();
            delete(config.buttons['Create an account']);
            config.buttons['Edit account'] = function () {
                row.remove();
                edit_data();
          };
    }
        dlg.dialog(config);

        function get_data() {
            var _em = jQueryOb(row.children().get(1)).text(),
                _mb= jQueryOb(row.children().get(2)).text(),
                _ema= jQueryOb(row.children().get(3)).text(),

            fname.val(_em);
            lname.val(_mb);
            email.val(_ema);

        }

        function save_data() {

   jQueryOb("#users tbody").append("<tr>" + "<td>" +fname.val()+ "</td>" + "<td>" +lname.val() + "</td>" + "<td>" 
        + email.val() + "</td>" + "<td><a class='edit' href=''>Edit</a></td>" + 
        "<td><span class='delete'><a href=''>Delete</a></span></td>" + "</tr>");
dlg.dialog("close");

var url = "addkliente.php"; // the script where you handle the form input.
var fn=fname.val();
var ln= lname.val();
var em= email.val();

    jQueryOb.ajax({
           type: "POST",
           url: url,
           data:'&fname='+ fn +'&lname='+ ln +'&email='+ em

         });

    return false; // avoid to execute the actual submit of the form.

    }

  };

  function edit_data(){
var dlg = jQueryOb("#dialog-form").clone();
        var fname = dlg.find(("#fn1")),
            lname = dlg.find(("#fn2")),
            email = dlg.find(("#fn3")),

      jQueryOb("#users tbody").append("<tr>" + "<td>" +fname.val()+ "</td>" + "<td>" +lname.val() + "</td>" + "<td>" 
        + email.val() + "</td>" + "<td><a class='edit'href=''>Edit</a></td>" + "<td><span class='delete'><a href=''>Delete</a></span></td>" + "</tr>");
dlg.dialog("close");

var url1 = "update.php"; // the script where you handle the form input.
var fname1= fname.val();
var lname1= lname.val();
var email1= email.val();

    jQueryOb.ajax({
           type: "POST",
           url: url1,
           data:'&fname='+ fname1 +'&lname='+ lname1 +'&email='+ email1
         });

    return false; // avoid to execute the actual submit of the form.

    };

    jQueryOb(document).on('click', 'td a.edit', function () {
        new_dialog('Edit', jQueryOb(this).parents('tr'));
        return false;
    });

    jQueryOb("#create-user").button().click(new_dialog);

});
jQueryOb(function delete_row(row){

    var dlg = jQueryOb("#dialog-form").clone();
    var id_klient = dlg.find(("#fn1"));
    var _del = jQueryOb(row.children().get(0)).text();

    id_klient.val(_del);
    var id_kl=id_klient.val();

    jQueryOb.ajax({
           type: "POST",
           url: deleteklient.php,
           data: '&id_klient='+ id_kl
         });


    jQueryOb(document).on('click', 'span.delete', function () {
        delete_row(this).closest('tr').find('td');
       jQueryOb(this).closest('tr').find('td').fadeOut(1000,

        function () {
            // alert($(this).text());
            jQueryOb(this).parents('tr:first').remove();
     });

        return false;
    });
});

`

2
Contributors
1
Reply
14
Views
3 Years
Discussion Span
Last Post by diafol
0

This code strikes me as overly complicated. You should be able to use one ajax run for update|insert|delete by having a 'mode' variable.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.