taz321 Posted January 18, 2008 Share Posted January 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86672-disabling-and-enabling-users/ Share on other sites More sharing options...
p2grace Posted January 18, 2008 Share Posted January 18, 2008 You would need an "active" field in your users table. Then instead of running a delete query you'd run an update query change the active field from 1 to 0. Quote Link to comment https://forums.phpfreaks.com/topic/86672-disabling-and-enabling-users/#findComment-442940 Share on other sites More sharing options...
taz321 Posted January 18, 2008 Author Share Posted January 18, 2008 Okay, abit confused, how can i amend my code below to do this ? Quote Link to comment https://forums.phpfreaks.com/topic/86672-disabling-and-enabling-users/#findComment-442945 Share on other sites More sharing options...
p2grace Posted January 18, 2008 Share Posted January 18, 2008 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86672-disabling-and-enabling-users/#findComment-442950 Share on other sites More sharing options...
taz321 Posted January 18, 2008 Author Share Posted January 18, 2008 so in my employee table, i would add an extra field called Active as an int. What do you mean by setting all active users to 1 ? Quote Link to comment https://forums.phpfreaks.com/topic/86672-disabling-and-enabling-users/#findComment-442966 Share on other sites More sharing options...
p2grace Posted January 18, 2008 Share Posted January 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86672-disabling-and-enabling-users/#findComment-442972 Share on other sites More sharing options...
taz321 Posted January 18, 2008 Author Share Posted January 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86672-disabling-and-enabling-users/#findComment-442974 Share on other sites More sharing options...
yaz Posted January 18, 2008 Share Posted January 18, 2008 You probably have to change the query where they login. If you match their pwds and usernames, add on the WHERE statement something like this WHERE Active = 1. Quote Link to comment https://forums.phpfreaks.com/topic/86672-disabling-and-enabling-users/#findComment-442983 Share on other sites More sharing options...
drummer101 Posted January 18, 2008 Share Posted January 18, 2008 But it still allows the same user which i had disabled to login. Did you see this part? After that you'll have to update your system to check whether or not the user is active before allowing them to login. Quote Link to comment https://forums.phpfreaks.com/topic/86672-disabling-and-enabling-users/#findComment-442987 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.