1

I am using php,mysql and ajax to delete record from a table. The problem is that the in MySQL_query it not getting the id it shows "id= undefined", i tried to pass the id to the query but i don't know where i went wrong i tried to print MySQL its shows

delete from 9xx WHERE id = undefinedArray
(
    [rowid] => undefined
    [supplier] => 9xx
)

can anyone tell me how to pass the id ...thanks

My ajax

$(".deletesuppliernetwork").live('click',function()
        {
         arr = $(this).attr('class').split( " " );
        var supplier=document.getElementById("supplier").value;

        if(confirm("Sure you want to delete this update?"))
        {
        $.ajax({
        type: "POST",
        url: "suppliernetwork/delete.php",
        data: "rowid="+arr[2]+"&supplier="+supplier,
        success: function(data){
                                                         $('.ajax').html($('.ajax input').val());
                                                         $('.ajax').removeClass('ajax');
                                                    }});
        }
        });

My html

<?php
include"db.php";

$supplier_id=$_GET['supplier_id'];

if($supplier_id!=""){

$sql=mysql_query("select * from $supplier_id order by country,networkname" );

while($rows=mysql_fetch_array($sql))
{

if($alt == 1)
        {
           echo '<tr class="alt">';
           $alt = 0;
        }
        else
        {
           echo '<tr>';
           $alt = 1;
        }

echo '  <td style="width:123px" class="edit supplier '.$rows["id"].'">'.$rows["supplier"].'</td>
                <td style="width:104px" class="edit rn '.$rows["id"].'">'.$rows["rn"].'</td>    
            <td style="width:103px" class="edit sc '.$rows["id"].'">'.$rows["sc"].'</td>    
            <td style="width:108px" class="edit comment '.$rows["id"].'">'.$rows["comment"].'</td>

            <td style="width:62px" class="deletesuppliernetwork '.$rows["id"].'"><img   src="/image/delete.png" style="margin:0 0 0 17px" ></td>                                

        </tr>';


}
}
?>

delete.php

<?php
    include"db.php";

$supplier=$_POST['supplier'];




        $rownum=$_POST['rowid'];  
        $sql="delete from $supplier WHERE id = ".$rownum."";

        print $sql;

        mysql_query($sql);  


    print_r($_POST);
?>

2 Answers 2

2
<td style="width:62px" class="deletesuppliernetwork '.$rows["id"].'"><img   src="/image/delete.png" style="margin:0 0 0 17px" ></td>     

the index of your ID is 1, that is second index. not 2.

$.ajax({
        type: "POST",
        url: "suppliernetwork/delete.php",
        data: "rowid="+arr[1]+"&supplier="+supplier,
        success: function(data){
                                                         $('.ajax').html($('.ajax input').val());
                                                         $('.ajax').removeClass('ajax');
                                                    }});
Sign up to request clarification or add additional context in comments.

2 Comments

thanks its worked but i want to hide the 'td' when its deleted.i think its after sucess
see the second answer by me, it will hide the row without needing to reload the complete page
1
var rowObj = $(this);    
$.ajax({
            type: "POST",
            url: "suppliernetwork/delete.php",
            data: "rowid="+arr[1]+"&supplier="+supplier,
            success: function(data){
                 $('.ajax').html($('.ajax input').val());
                 $('.ajax').removeClass('ajax');
                  $(rowObj).parents("tr:first").hide();
            }});

this should hide your complete row.

2 Comments

@arokia Please the updat above $(this).parents("tr:first").hide();
when you are in the Success block, this would change to local scope, create variable as above updated answer. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.