是否有可能从PHP中的Mysql动态删除数据?

时间:2017-03-07 04:42:40

标签: php jquery mysql sql-delete

我正在尝试删除与一个客户端关联的所有表中的所有行。我在Mysql中尝试了查询,它运行得很好。当我手动输入client_id时,它也适用于PHP。但是当我尝试使用从jQuery填充的动态变量时,没有任何反应。没有错误,没有任何内容被删除我检查过变量中是否有数据,是的。所以我的理解是不可能动态删除数据?

脚本

<script>
      $('#deleteClientModal').on('show.bs.modal',function (dclient){
                              var button = $(dclient.relatedTarget);
                              //get data
                              var deleteClientid = button.data('clientidentification');
                              //append to modal
                              var modal = $(this);
                              modal.find('#deleteClientid').val(deleteClientid );
                        });
</script>

modal.php

    <button data-clientidentification="<?=$client['id'];?>" title="Delete Client" type="button" data-toggle="modal" data-target="#deleteClientModal"></button>


        <form id="removeclient" method="POST" action="core/query.php">
    <!-- Modal -->
    <div id="deleteClientModal" class="modal fade" role="dialog">
//short Modal for example
                  <input name="removeClientid " id="deleteClientid" type="text" class="formBlock"  value=""/> 
            <input name="removeClient" id="submit" type="submit" class="formBlock btn btn-success"  value="Yes"/>
             <button type="button" class="close btn" data-dismiss="modal">Cancel</button>
              </div>
        </form>

query.php

//deleteClient
  if(isset($_POST['removeClient'])){
//retrieve value from form
 $removeClientid = $_POST['removeClientid'];
//update clients by deleting the row
$deleteClient="DELETE `clients`, `projects`, `employeeprojects`, `employeeprojects_conversation` FROM `clients` INNER JOIN `projects` ON clients.id=projects.client_id INNER JOIN `employeeprojects` ON projects.project_id=employeeprojects.project_id INNER JOIN `employeeprojects_conversation` ON employeeprojects.project_id=employeeprojects_conversation.project_id WHERE clients.id='$removeClientid'";
//execute query
if ($db->query($deleteClient) === TRUE) {
    //reset tables to 1 if table empty
 header('Location: ' . $_SERVER['HTTP_REFERER']);
 exit;
} else {
    echo "Error deleting record: " . $db->error;
}
$db->close();
  }

0 个答案:

没有答案