JQuery-Tabledit only updating one column at a time (What is wrong with my code)

问题: I'm using a JQuery-Tabledit to update the MySQL table. the issue I'm facing is that when I update the cell value of the first column, same row value of the second column...

问题:

I'm using a JQuery-Tabledit to update the MySQL table.

the issue I'm facing is that when I update the cell value of the first column, same row value of the second column disappeared.

I'm not able to figure out what I'm doing wrong here.

Here is my JQuery-Tabledit code

$('#example1').Tabledit({
url: 'logic-edit-delete.php',
editButton: false,
deleteButton: false,
columns: {
    identifier: [0, 'id'],
    editable: [[4, 'Status', '{"": "Select","P": "Present", "PL": "Planed Leave", "UPL": "UnPlaned Leave", "WO": "Week Off", "COff": "Comp Off", "PH": "Public Holiday", "UPHD": "UnPlaned Half Day", "PHD": "Planed Half Day", "LWP": "Leave Without Pay"}'], [5, 'Leavetype', '{"": "Select","SL": "Sick Leave", "CL": "Casual Leave"}']]

},

And PHP code to update my SQL table

<?php

include('db-connect.php');

$input = filter_input_array(INPUT_POST);

if ($input['action'] === 'edit') 
{   
    $sql = "UPDATE attendance SET Status ='" . $input['Status'] . "', Leavetype ='" . $input['Leavetype'] . "'" ." WHERE id='" . $input['id'] . "'";

    mysqli_query($con,$sql);
} 
if ($input['action'] === 'delete') 
{
    mysqli_query($con,"DELETE FROM attendance   WHERE id='" . $input['id'] . "'");
} 


mysqli_close($mysqli);

echo json_encode($input);
?>

Screenshots for your refrence Images enter image description here enter image description here enter image description here


回答1:

It's happening due to you are trying to update both columns every time. You just need to update on condition based like below:

    if(isset($input['Status']) && !empty($input['Status'])) {
        $sql = "UPDATE attendance SET Status ='" . $input['Status'] . "' WHERE id='" . $input['id'] . "'";   
    } else if(isset($input['Leavetype']) && !empty($input['Leavetype'])) {
        $sql = "UPDATE attendance SET Leavetype ='" . $input['Leavetype'] . "' WHERE id='" . $input['id'] . "'";
    }
  • 发表于 2019-03-07 23:55
  • 阅读 ( 254 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除