I'm just starting out with PHP and am a bit lost. I feel like it's probably something small I'm missing but when I click the delete button it does not work. It doesn't give me any errors, the button just clicks and does nothing. Any ideas why? I've spent hours trying to figure it out but I have come up with nothing. I've done add user and show users in much the same way and it works but this has me stumped. Thanks in advance :)
users.controller.php
static public function DeleteUserController(){
if(isset($_GET["userId"])){
$table ="users";
$data = $_GET["userId"];
var_dump($data);
$answer = UserModel::DeleteUserModel($table, $data);
if($answer == "ok"){
echo'<script>
swal({
type: "success",
title: "User has been Deleted",
showConfirmButton: true,
confirmButtonText: "Close"
}).then(function(result){
if (result.value) {
window.location = "users";
}
})
</script>';
}
}
}
users.model.php
static public function DeleteUserModel($table, $data){
$stmt = Connection::connect()->prepare("DELETE FROM $table WHERE id = :id");
$stmt -> bindParam(":id", $data, PDO::PARAM_STR);
if ($stmt->execute()) {
return 'ok';
} else {
return 'error';
}
$stmt -> close();
$stmt = null;
}
users.js
$(".btnDeleteUser").click(function(){
var userId = $(this).attr("userId");
var username = $(this).attr("username");
swal({
title: 'Are you sure you want to delete user?',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText: 'Cancel',
confirmButtonText: 'Confirm'
}).then((result)=>{
if(result.value){
window.location = "index.php?route=users&userId="+userId+"&username="+username;
}
})
})
users.php
<button class="btn btn-danger btnDeleteUser" userId="'.$value["id"].'" username="'.$value["user"].'"><i class="fa fa-times"></i></button>
users.php
<?php
$deleteUser = new ControllerUsers();
$deleteUser -> DeleteUserController();
?>
index.php
<?php
require_once "controllers/template.controller.php";
require_once "controllers/products.controller.php";
require_once "controllers/sales.controller.php";
require_once "controllers/users.controller.php";
require_once "models/products.model.php";
require_once "models/sales.model.php";
require_once "models/users.model.php";
$template = new TemplateController();
$template -> tempController();