如何使用php更新datetime字段?

时间:2018-03-05 09:18:23

标签: javascript php jquery sql

我有这个功能,我可以更新我的输入字段,我有一个fetch.php从我的sql获取数据。

所以这是我的输入字段 - > [样本图片 - 输入字段] [1]
然后,当我点击更新时,它返回此 - > [示例图片 - 更新输入字段] [2]

我的问题是每当我更新它时会返回除日期和时间之外的字段中的所有数据?我该如何解决这个问题?

以下是我的代码。 TYVM。

<div class="col-sm-2">
    <input type="datetime-local" name="date_submitted" id="date_submitted" class="form-control" placeholder="Date Submitted" style="width: 120%;" />
</div>

<script>
    $(document).ready(function() {
        addDocu();

        function addDocu() {
            var action = "select";
            $.ajax({
                url: success: function(data) {
                    alert(data);
                    addDocu();
                }
            });
        } else {
            alert("All Fields are Required");
        }
    });
    $(document).on('click', '.update', function() {
        var id = $(this).attr("id");
        $.ajax({
            url: "fetch.php",
            method: "POST",
            data: {
                id: id
            },
            dataType: "json",
            success: function(data) {
                $('#action').text("Save");
                $('#docu_id').val(id);
                $('#code').val(data.code);
                $('#doc_kind').val(data.doc_kind);
                $('#date_submitted').val(data.date_submitted);
                $('#remarks').val(data.remarks);

            }
        })
        "select.php",
        method: "POST",
            data: {
                action: action
            },
            success: function(data) {
                $('#code').val('');
                $('#doc_kind').val('');
                $('#date_submitted').value('');
                $('#remarks').val('');
                $('#action').text("Add");
                $('#result').html(data);
            }
    });
    }
    $('#action').click(function() {
        var docCode = $('#code').val();
        var docKind = $('#doc_kind').val();
        var dateSubmitted = $('#date_submitted').val();
        var docRemarks = $('#remarks').val();
        var id = $('#docu_id').val();
        var action = $('#action').text();
        if (docCode != '' && docKind != '' && dateSubmitted != '') {
            $.ajax({
                url: "action.php",
                method: "POST",
                data: {
                    docCode: docCode,
                    docKind: docKind,
                    dateSubmitted: dateSubmitted,
                    docRemarks: docRemarks,
                    id: id,
                    action: action
                },
                success: function(data) {
                    alert(data);
                    addDocu();
                }
            });
        } else {
            alert("All Fields are Required");
        }
    });
    $(document).on('click', '.update', function() {
        var id = $(this).attr("id");
        $.ajax({
            url: "fetch.php",
            method: "POST",
            data: {
                id: id
            },
            dataType: "json",
            success: function(data) {
                $('#action').text("Save");
                $('#docu_id').val(id);
                $('#code').val(data.code);
                $('#doc_kind').val(data.doc_kind);
                $('#date_submitted').val(data.date_submitted);
                $('#remarks').val(data.remarks);

            }
        })
    });
</script>

if(isset($_POST["id"]))  
{
    $output = array();  
    $procedure = "  
    CREATE PROCEDURE whereDocu(IN docu_id int(11))  
    BEGIN   
    SELECT * FROM officesectb WHERE id = docu_id;  
    END;   
    "; 

function convert ($rem) {
$rem = trim($rem);
return preg_replace('/<br(\s+)?\/?>/i', "\n", $rem);
}
    if(mysqli_query($connect, "DROP PROCEDURE IF EXISTS whereDocu"))  
    {  
        if(mysqli_query($connect, $procedure))  
        {
            $query = "CALL whereDocu(".$_POST["id"].")";  
            $result = mysqli_query($connect, $query);  
            while($row = mysqli_fetch_array($result))  
            {
                $rem = $row["remarks"];

                  $output['code'] = $row["code"];  
                $output['doc_kind'] = $row["doc_kind"];  
                $output['date_submitted'] = $row['date_submitted']; 
                $output['remarks'] = convert($rem);
            }  

            echo json_encode($output);  
        }  
    }  
} 

0 个答案:

没有答案