JS : Fixed by godot!
/* Data Delete Starts Here */
$(".delete-file").click(function()
{
var name = $(this).attr("name");
var file_id = $(this).attr("id");
var active_user = document.getElementById("username").value;
if(confirm('Sure to Delete ' +name+ '?'))
{
$.ajax({
url: 'suf-delete.php',
type: 'post',
async: false,
data: {'file_id':file_id ,'active_user':active_user},
success: function(response){
$("#file_table"+file_id).fadeOut('slow');
},
error: function(error){
console.log(error.responseText);
//you could debug your php code if some error raises
}
});
}
return false;
});
/* Data Delete Ends Here */
PHP: Working Fine (suf-delete.php)
elseif($_POST['file_id'] && $_POST['active_user'])
{
$file_id = $_POST['file_id'];
$active_user = $_POST['active_user'];
$crud->filesDelete($file_id,$active_user);
}
Im now having a problem with my class crud.
I think Its just my query. Im trying to make activity log, delete, select and unlink Item using my code provided below.
Please check this:
Class Crud
public function filesDelete($file_id,$active_user)
{
$stmtFiles = $this->conn->prepare('SELECT * FROM tbl_files WHERE file_id=:file_id');
$stmtFiles->execute(array(":file_id"=>$file_id));
$unFile=$stmtFiles->fetch(PDO::FETCH_ASSOC);
$userStmt = $this->conn->prepare('SELECT * FROM tbl_login WHERE username=:username');
$userStmt->execute(array(":username"=>$active_user));
$fetch = $userStmt->fetch(PDO::FETCH_ASSOC);
$activity = "Deleted the file ".$unFile['file_name'];
if($fetch['access_type']=="Design2K18ADMIN") {
$type = "Administrator";
}
elseif ($fetch['access_type']=="Design2K18MANAGER") {
$type = "Manager";
}
elseif ($fetch['access_type']=="Design2K18MODERATOR") {
$type = "Moderator";
}
elseif ($fetch['access_type']=="Design2K18SIMPLE") {
$type = "Simple";
}
$actLog = $this->conn->prepare("INSERT INTO activity_log(username, activity, type) VALUES(:username, :activity, :type)");
$actLog->execute(array(":username"=>$active_user, ":activity"=>$activity, ":type"=>$type));
$stmtSelFol = $this->conn->prepare('SELECT * FROM tbl_section WHERE sec_id=:sec_id');
$stmtSelFol->execute(array(":sec_id"=>$unFile['sec_id']));
$unFol=$stmtSelFol->fetch(PDO::FETCH_ASSOC);
unlink("../Files/".$unFol['sec_folder']."/".$unFile['file_name']);
$stmtDelFile = $this->conn->prepare('DELETE FROM tbl_files WHERE file_id=:file_id');
$stmtDelFile->execute(array(":file_id"=>$file_id));
return true;
}
I have confirm that My js and php works fine by saving the logs in error.php
I save the value of file_id and active_user in my error.txt file.
9Daren appears which is the value(id) of Item and the current session user is Daren.
Please help me check my public function why It does not do anything.
</div>