PHP更新-Ajax错误,但行更新

时间:2018-06-24 11:11:51

标签: php html ajax

当我在获取数组中使用更新模式时,发生了一些奇怪的情况,这是我的代码,用于使用php数组生成表:

while($row = mysqli_fetch_array($tablequery)) {
if ($id != -1 && $id != $row['Date']) {
    echo '</tbody>';
    echo '</table>';
}

if ($id != $row['Date']) {
    echo '<div class="container omhdatebreak"><i class="material-icons floatleft">today</i><div>'.date("d/m/Y", strtotime($row['Date'])).' - '.date("l",strtotime($row['Date'])).'</div></div>
        <table class="table omhtablebreak"> 
            <thead>
         <tr>
            <th class="table-header" width="5%"></th> 
            <th class="table-header" width="10%"></th>   
            <th class="table-header" width="30%">Time</th>
            <th class="table-header" width="30%"> Customer </th>
            <th class="table-header" width="25%" colspan="2"></th>
          </tr>
    </thead>';

    $id = $row['Date'];
}?>

    <tbody>     
        <tr class="table-row" id="row-<?php echo $row["LineRef"]; ?>">
            <?php $ColChange = $row["Status"];
if ($ColChange == "New") {
    echo '<td class="table-row "><i class="material-icons" style="width:10px; color:#109aee;" title="New Appointment"> notifications</i></td>';
} else {
    echo '<td class="table-row"><i class="material-icons" style="width:10px; color:#328132;" title="Completed Appointment"> check_circle</i></td>';
}?>
            <td class="table-row"><?php echo $row["Status"]; ?></td>
            <td class="table-row"><?php echo $row["StartTime"]; ?> - <?php echo $row["EndTime"]; ?></td>
            <td class="table-row"><?php echo $row["Firstname"]; ?></td>
            <!-- action -->
            <td class="table-row" colspan="2">
                <a href="#updatemodal<?php echo $row["LineRef"]; ?>" data-target="#updatemodal<?php echo $row["LineRef"]; ?>" data-toggle="modal" class="link btn btn-info"><i class="material-icons"  title="Update Appointment">edit</i></a>

                <div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" id="updatemodal<?php echo $row["LineRef"]; ?>">
    <!--INSERT MODAL-->
    <div class="omhmodal modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Add A New Appointment</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
<form method="post">
    <input type="hidden" id="<?php echo $row["LineRef"]; ?>">
<div class="row">
<div class="col">
  <label>Name</label>
  <input type="text" name="fnameupdate" id="fname<?php echo $row["LineRef"]; ?>"   class="form-control fnameupdate" value="<?php echo $row["Firstname"]; ?>" />
</div>
    </div>
  <div class="row">
                     <div class="col">                         
                        <label class="CustomLabel">Date</label>  
                            <input type="date" name="OMHdateupdate" id="OMHdate<?php echo $row["LineRef"]; ?>" class="form-control" value="<?php echo $row["Date"]; ?>"/>
                     </div>
                    </div>
                <div class="row">  
                     <div class="col">
                        <label class="CustomLabel">From</label>                             
                        <input type="time" name="OMHstartupdate" id="OMHstart<?php echo $row["LineRef"]; ?>" class="form-control" value="<?php echo $row["StartTime"]; ?>">
                     </div>
                     <div class="col">
                        <label class="CustomLabel">To</label>                             
                        <input type="time" name="OMHendupdate" id="OMHend<?php echo $row["LineRef"]; ?>" class="form-control" value="<?php echo $row["EndTime"]; ?>">
                     </div>
                 </div>


                    <div class="form-group">
                        <label class="CustomLabel">Appointment Information</label>  
                 <textarea name="notesupdate" id="notes<?php echo $row["LineRef"]; ?>" class="form-control"><?php echo $row["Notes"]; ?></textarea>  
                 </div>

                      <div class="center">
                        <input type="radio" id="status1" name="statusupdate" value="New" checked>
                        <label for="contactChoice1">New</label>

                        <input type="radio" id="status3" name="status" value="In Progress">
                        <label for="contactChoice3">In Progress</label>

                        <input type="radio" id="status4"name="status" value="Completed">
                        <label for="contactChoice3">Completed</label>                            
                    </div>
                        <button type="submit" onclick="updateModal(<?php echo $row["LineRef"]; ?>)" class="btn btn-success omhformsubmit floatleft"><i class="material-icons floatleft">add_circle</i><div>update Appointment</div> 
</button>

        </div>
                <div class="modal-footer">

                 </div>
        </div>
    </div>

</div>
             </td>
        </tr>
    </tbody>

        

在更新约会按钮上,有一个正在调用的函数,如下所示:

    function updateModal(str){
        var id = str;
        var name = $('#fname'+str).val();         
        $.ajax({
            type: "POST",
            url: "update.php",
            data: {name:name, lineref:id},
            success:function(data){  
                       window.alert("Appointment has been Updated");
                    }  
        });
    }

因此,当更新成功时,我希望在屏幕上看到一个警报,但是当我单击“更新”按钮时,警报不会出现,但是如果我回头查看MYSQL中的表,则该行已更新与新的信息。我的update.php文件如下所示:

<?php
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);


if (mysqli_connect_errno()) {
die("Database connection failed: " . mysqli_connect_error() . " (" . 
mysqli_connect_errno() . ")"
);
 }

$fname = $_POST['name'];
$OMHid = $_POST['lineref'];


$updatequery  =   "UPDATE appointments SET Firstname = '$fname' Where LineRef = $OMHid";

    $result = mysqli_query($connection, $updatequery);

mysqli_close($connection);

有人会知道是什么会导致该功能无法成功显示警报吗?

0 个答案:

没有答案
相关问题