我做了一个表格,以便可以使用值更新数据库。我的问题是它与其他按钮冲突。其他按钮正在处理AJAX请求。但是,当它们处于表单形式时,它们将无法工作。所以我需要另一个解决方案。
我试图将最后一个按钮也设为AJAX请求,但无法获取发布值。
我所知道的:
function getUsers($orgID, $type)
{
require 'functions/conn.php';
$sql = "SELECT users.*, parts.*, keuze.* FROM ((users INNER JOIN parts ON users.part_id = parts.part_id) INNER JOIN keuze ON users.keuze_ID = keuze.ID) WHERE users.org_id = '" . $orgID . "' AND users.active IN ($type);";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo '<tr id="' . $row['user_id'] . '" class="changeUser">';
echo ' <td><input type="checkbox" name="checked[]" value="' . $row['user_id'] . '"></td>';
echo ' <td>' . $row['fnln'] . '</td>';
echo ' <td>' . $row['username'] . '</td>';
echo ' <td>' . $row['name'] . '</td>';
echo ' <td>' . $row['keuze'] . '</td>';
echo ' <td>';
if ($row['active'] == 0 && $row['eind_tijd'] != 0 || $row['active'] == 2 && $row['eind_tijd'] != 0) {
echo ' <button class="button button-green" onclick="approveOne('.$row['user_id'].', '.$_SESSION['org_id'].')">Approve</button>';
}
echo ' <button class="button button-red" onclick="deleteFromRelation(' . $row['user_id'] . ');">Delete</button><br/>';
echo ' </td>';
echo '</tr>';
}
}
}
?>
<form action="functions/save/saveAllusers.php" method="post" enctype="multipart/form-data">
<div class="form-group col-md-12"><select name="tijd" class="form-control col-md-12" id="Eindtijd"><?php getTime(); ?></select></div>
<input type="submit" name="submit" id="submitChangeUser" class="button button-green" value="Change time"/>
<?php getUsers($_SESSION['org_id'], 0); getUsers($_SESSION['org_id'], 2); ?>
</form>
AJAX请求(PHP中的按钮)
function approveOne(user, org) {
swal({
title: 'Are you sure to approve this users?',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Approve user'
}).then(function () {
$.ajax({
url: "functions/save/approveUser.php",
type: "POST",
data: {user, org},
success: function (data) {
swal(
'Approved!',
'You have approved the selected user.',
'Success'
);
$("#newUsers").hide(250);
},
error: function (jXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
}
function deleteUser(userID) {
swal({
title: 'Are you sure you want to delete your user account?',
text: "You can't revert this step.",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Delete'
}).then(function () {
$.ajax({
url: "functions/delete/deleteUser.php",
type: "POST",
data: {userID},
success: function (data) {
swal({
title: 'Deleted!',
text: 'You have deleted the user.',
type: 'success',
}).then (function(){
//redirect de user
location.reload();
});
},
error: function (errorThrown) {
alert(errorThrown);
}
});
});
}
我所期望的是,我可以更新行,就像我可以正确知道的那样,并且其他按钮可以正常工作。如果单击批准或删除按钮(php中的按钮),则它希望与html中的按钮相同。当然,它给出了无法插入的错误。但是按钮并不是为此而准备的……当它们离开表格时,它的工作原理就像正常情况一样。