我有一个脚本,询问是否确定要添加新数据。我的php没问题,因为当我想在禁用脚本的情况下插入数据时,它会正常插入。但是当我的脚本没有被禁用时,它将不再插入...我不知道为什么我没有任何错误(可能是因为有2个不同的文件)。
我的脚本
$(document).on("click", ".btnAddSubcat", function(e) {
event.preventDefault();
var subcatid = $('.CatEdit-select').val();
var subcatvalue = $('.subCat').val();
var subcatprocedure = $('.subProcedure').val();
var url = "../service/functions/postActions.php";
swal({
title: 'Add a new sub-category?',
text: "Are you sure to Add this sub-category?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, Add it!'
}).then(function () {
$.ajax({
type: 'POST',
url : url,
data: {
'cat-select': subcatid,
'subCat': subcatvalue,
'Procedure': subcatprocedure
},
success: function (data) {
swal({
title: 'Add!',
text: "You Add a sub-category!",
type: 'success',
confirmButtonColor: '#3085d6',
confirmButtonText: 'OK'
}).then(function () {
window.location.reload();
})
}
});
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
如果您需要我的php插入功能或其他让我知道的信息
编辑
我的PHP函数
function AddSubCat() {
$Catid = $_POST['cat-select'];
$Subnaam = $_POST['subCat'];
$procedure = $_POST['Procedure'];
include '../../../include/dbConnection/dbcon.php';
//set update query ready for database, with info from the Ajax POST method for update.
$sqladdSubCat = 'INSERT INTO `*****`(`naam`,`Werkwijze`) VALUES ("'.$Subnaam.'","'.$procedure.'")';
//if query is done right then 'Record updated successfully'
if (mysqli_query($conn, $sqladdSubCat))
{
//get new colourId
$newUpload_id = mysqli_insert_id($conn);
//set update query hw_algoritmes thee cat id that may have change.
$sqlalgotime = 'INSERT INTO `*****`(`categorie_id`, `subcategorie_id`) VALUES ("'.$Catid.'","'.$newUpload_id.'")';
//if query is done right then 'Record updated successfully'
if (mysqli_query($conn, $sqlalgotime)) {
//check if there is a new front image add
if ($_FILES['HWVideo']['name'] == "") {
//Empty
} else {
uploadVideoHw($_FILES['HWVideo'], $newUpload_id);
}
} else {
echo "Error updating record: " . mysqli_error($conn);
}
header('Location: /cms/service/index.php');
} else {
echo "Error updating record: " . mysqli_error($conn);
// header('Location:../../Categorieen');
}
}