Firstly, please forgive me if i don't give enough info in my question, i'm new to the developer scene after just landing myself an amazing opportunity as a junior software developer role a few weeks ago.
I have a project i'm working on which is a basic CRUD management system. I have a login process and user accounts all setup but i would like certain things to require "Admin" privileges like deleting items from my inventory.
So currently everything works as is (just no admin checking)
i have made this function in my config.php (which is included on every page through the header)
function checkAdmin($conn)
{
$id = $_SESSION['member_id'];
$sql = "SELECT admin FROM members WHERE id = $id";
$query = mysqli_query($conn, $sql);
$rs = mysqli_fetch_array($query);
$admin = $rs['admin'];
if($admin == 1){
return true;
}else{
return false;
}
}
So my question is, how do i then pass that value "true/false" into my query. Im using jQuery/Ajax to do my queries but i understand this would be handed on my "ajax.php" page where all my queries are. my current code is:
if(isset($_GET['deleteID']))
{
if('checkAdmin' == true){
$id = $_GET['deleteID'];
$sql = "DELETE FROM members WHERE id=$id";
mysqli_query($conn, $sql);
recordLog($conn, "Members", "Removed user #$id");
$data = [
'success' => true
];
}else{
$data = [
'error' => 'Admin Privileges Required'
];
}
echo json_encode($data);
}
the actual code in itself works, without the If(checkAdmin ==
statement but i dont think i'm on the right lines with it.
Thanks in advance for any help :) please let me know if any more info is needed