更新错误并在php mysql中插入查询

I am trying to update seen(a bool in the database) if the seen button is clicked and delete a row if the delete button is clicked. But it doesn't seem to work nor do I get any data(mysql_error) back. But the last else part works and I get the data.

This is the php code :

if(isset($_POST["seen"])){
    $fid=$_POST["id"];
    $sql="UPDATE feedback SET seen=1 WHERE ID=$fid";
    mysql_query($sql,$con);
    echo mysql_error($con);
} else if(isset($_POST["delete"])){
    $fid=$_POST["id"];
    $sql="DELETE from feedback WHERE ID=$fid";
    mysql_query($sql,$con);
    echo mysql_error($con);
} else{
    $sql="SELECT * FROM feedback";
    $result=mysql_query($sql,$con);
    while($row=mysql_fetch_array($result)){
        $jsonData[]=$row;
    }
    echo json_encode($jsonData);
}

and js code:

$("#seen").click(function(){
    $.post("main_php.php",{},function(data){
        alert(data);
    }); 
});

$("#delete").click(function(){
    var fid = $('#ID').val();
    $.post("main_php.php",{id:fid},function(data){
        console.log(data);
    }) 
});

Please tell me what may be wrong with it!!!!

seen and delete are the names of buttons btw

Your jQuery POST is not setting the "seen" or "delete". So when the PHP executes, it is just falling through to that last else.

In the jQuery, set "seen" or "delete" to true (or anything else, but they need to be set) and you should be good.

In Ajax submit, we have to explicitly submit the elements you want. To fix it, edit your code like below

$("#seen").click(function(){
    $.post("main_php.php",{seen:1},function(data){
        alert(data);
    }); 
});

$("#delete").click(function(){
    var fid = $('#ID').val();
    $.post("main_php.php",{id:fid,delete:1},function(data){
        console.log(data);
    }) 
});

Set the 'seen' / 'delete' in jQuery to true as they are not set. That might solve the problem.