Jump to content

Disabling and enabling users


taz321

Recommended Posts

Im wondering if anyone can help me on this.

 

I have a helpdesk system with 3 login's for 3 different users.

 

One of the users is the admin user, and they can either add, delete or edit login details for the other two users.

 

Im having the following problem -

 

1) Once i populate all tables in my database (all having various primary & foriegn keys) with data, i am unable to delete users in the admin section.

I have been told this maybe because i need cascading foreign keys (told this is risky as could delete the whole database) i hope you follow me so far.

 

Instead of going through with this risk, instead of deleting users, i have heard that you can disable them and then re-activate them.

 

Could anyone tell me how you do this ?

 

This is my code for deleting -

 

<?php

require "connect.php";

$employeeID = $_GET['employeeID'];

$query =  "delete from employee where employeeID = ".$employeeID;

$result = mysql_query($query, $connection)

or die ("Unable to perform query<br>$query");

header("Location: deletepersonScreen.php");

exit();

?>

 

Thanks

Link to comment
Share on other sites

Alright, first in your database table you need to have a "active" field as an small int.  Then set all of your active users to "1".  After doing that, to disable a user you'd use the following code.

 

<?php
require "connect.php";
$employeeID = $_GET['employeeID'];
$query =  "UPDATE `employee` SET `active` = '0' WHERE `employeeID` = '$employeeID'";
$result = mysql_query($query, $connection)
or die ("Unable to perform query
$query");
header("Location: deletepersonScreen.php");
exit();
?>

Link to comment
Share on other sites

Correct.  What I meant by that was you have to set the active field for all the users you current have to 1, because by default it'll set them all the zero.  After that you'll have to update your system to check whether or not the user is active before allowing them to login.

Link to comment
Share on other sites

i have implemented the code you have given me, and i have added the data "1" in the active record of the table.

So when i submit the request to disable a user, in the database i can see that the "1" has turned to a "0" which should mean that the user wouldnt be allowed to login.

 

But it still allows the same user which i had disabled to login.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.