PRodgers4284 Posted March 15, 2008 Share Posted March 15, 2008 I am working on a basic admin facily for a website and i want to be able to disable user accounts. I have a field in the database table called "active", I basically want to set this to "0" to disable the account. How do i set the value of the active field to 0 using the query below? Can anyone help? I have marked the line ############ where im having difficulty. I have the following code: <?php $username = $_GET['username']; if (isset($_POST['submit'])) { $error_stat = 0; $forename_message = ''; $surname_message = ''; $email_message = ''; $mobile_message = ''; $dob_message = ''; $location_message = ''; $forename = trim($_POST['forename']); $surname = trim($_POST['surname']); $email = trim($_POST['email']); $mobile = trim($_POST['mobile']); $dob = trim($_POST['dob']); $location = trim($_POST['location']); } if (isset($_POST['submit']) && $error_stat == 0) { mysql_query("UPDATE users SET active="0" WHERE username=$username"); ################ ?> <br /> <a href="index.php">Back to main page</a> <br /> <br /> <br /> User account has been disabled . <?php } else { $account = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='$username'")); ?> Quote Link to comment Share on other sites More sharing options...
PRodgers4284 Posted March 15, 2008 Author Share Posted March 15, 2008 I have modified the code but im not sure of the query is right <?php $username = $_GET['username']; if (isset($_POST['submit'])) { mysql_query("UPDATE users SET active='1' WHERE username=$username"); ?> <br /> <a href="index.php">Back to main page</a> <br /> <br /> <br /> You have successfully updated your account . <?php } else { $account = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='$username'")); ?> Quote Link to comment Share on other sites More sharing options...
syed Posted March 15, 2008 Share Posted March 15, 2008 Hi PRodgers4284 Your sql query is correct but I would not use username to update your users table. You should use the users id to update the table. I am assuming the following. In your admin area, show list of users, with disable link next to each users name, when link is clicked send userid to disable.php In disable.php, update users table and set active=0 where userid = $_REQUEST['userid'], where active=0 is to disable the user. Then in your login scrips for users, check active=1, where active=1 is not disabled. If disabled print message. I hope that helps. Quote Link to comment Share on other sites More sharing options...
PRodgers4284 Posted March 15, 2008 Author Share Posted March 15, 2008 Hey thanks for the reply, i know what ur saying about the username, but the username for each user is unique in the application, this is checked within the registration script, it checks if the username already exists. I got the disable account working, but i now need to include an enable option, ive tried the query below but it doesnt update the table. It works fine when disabling the accounts, using active='0' in the query. I thought it was only a matter of changing the value being set for active in the query. $username = $_GET['username']; if (isset($_POST['submit'])) { mysql_query("UPDATE users SET active='1' WHERE username=$username"); Quote Link to comment 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.