更新textarea和datetime

时间:2018-03-02 16:45:21

标签: php jquery sql

好吧,我有date_submitted和remarks的这些输入字段。我的date_submitted是一个datetime-local的输入类型,我的备注是textarea标签。我有一个功能,我可以在其中更新我输入的数据。 所以这是我的例子问题:

离。我输入03/03/2018 12:31 AM然后点击添加将其添加到数据库中,现在当我要更新它时,它只显示这个mm / dd / yyyy - : - - 而不是03/03/2018 12:31 AM
恩。对于评论,我输入时 的你好
世界

然后添加它然后更新它,它显示在textarea字段中 你好//插入br标签
World // insert br tag

所以我的问题是,每当我更新数据时,我将如何删除br标签?我在这个中使用了nl2br。每当我点击更新按钮时,我输入的日期怎么样仍会显示? 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>
            <div class="col-sm-3">
                <textarea name="remarks" id="remarks" class="form-control" placeholder="Remarks" rows="2" style="margin-left:13%;"></textarea>
            </div>

                <div class="col-sm-2">
                    <input type="hidden" name="id" id="docu_id" />
                        <button class="button add" name="action" id="action" style="margin-left: 16%;">Add</button>
                </div>
                <br><br>

脚本

<script> 

$(document).ready(function(){
        fetchDocu();                
        function fetchDocu()
        {
            var action = "select";
            $.ajax({
                url: "select.php",
                method: "POST",
                data: {action:action},
                success: function(data){
                    $('#code').val('');  
                    $('#doc_kind').val('');
                    $('#date_submitted').val('');  
                    $('#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);  
                            fetchDocu();  
                        }  
                    });  
                    }  
                    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.docRemarks);  

                }  
           })  
    });

action.php的

if($_POST["action"] == "Save")  
{  
    $code = mysqli_real_escape_string($connect, $_POST["docCode"]);  
    $doc_kind = mysqli_real_escape_string($connect, $_POST["docKind"]);  
    $date_submitted = mysqli_real_escape_string($connect, $_POST["dateSubmitted"]);  
    $remarks = mysqli_real_escape_string($connect, $_POST["docRemarks"]);

    $procedure = "  
        CREATE PROCEDURE updateDocu(IN docu_id int(11), docCode varchar(20), docKind varchar(150), dateSubmitted varchar(150), docRemarks varchar(150))  
        BEGIN   
        UPDATE officeSecTB SET code=docCode, doc_kind=docKind, date_submitted=dateSubmitted, remarks=docRemarks
        WHERE id = docu_id;  
        END;   
    ";

    if(mysqli_query($connect, "DROP PROCEDURE IF EXISTS updateDocu"))  
    {  
        if(mysqli_query($connect, $procedure))  
        {  
            $query = "CALL updateDocu('".$_POST["id"]."', '".$code."', '".$doc_kind."','".$date_submitted."', '".$remarks."')";  
            mysqli_query($connect, $query);  
            echo 'Data Updated';  
        }  
    }  
}  

这就是我显示输出的方式

if(mysqli_num_rows($result) > 0)  
                {  
                    while($row = mysqli_fetch_array($result))  
                    {  
                        $output .= '  

                          <tbody>
                            <tr>  
                                  <td>'.$row["code"].'</td>  
                                  <td>'.$row["doc_kind"].'</td>
                                  <td>'.date('d M Y - H:i A', strtotime($row['date_submitted'])).'</td> 
                                  <td>'.nl2br($row["remarks"]).'</td> 

                                  <div class="row">
                                    <td>
                                      <div class="col-sm-6">
                                        <button name="update" id="'.$row["id"].'" class="button update btn-xs">Update</button>
                                      </div>
                                      <div class="col-sm-6">  
                                        <button name="delete" id="'.$row["id"].'" class="button delete btn-xs">Delete</button>
                                      </div>
                                    </td>  
                                  </div>
                            </tr>
                          </tbody>

                        ';  
                    }  
                }  

对不起,很长的帖子。提前谢谢。

fetch.php

<?php
    $connect = mysqli_connect("localhost","root", "", "ustjhsdts");  
    if(isset($_POST["id"]))  
    {
        $output = array();  
        $procedure = "  
        CREATE PROCEDURE whereDocu(IN docu_id int(11))  
        BEGIN   
        SELECT * FROM officesectb WHERE id = docu_id;  
        END;   
        "; 

        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))  
                {
                      $output['code'] = $row["code"];  
                    $output['doc_kind'] = $row["doc_kind"];  
                    $output['date_submitted'] = $row['date_submitted'];
                    $output['remarks'] = nl2br($row["remarks"]);
                }  

                echo json_encode($output);  
            }  
        }  
    } 


?>

0 个答案:

没有答案