Jump to content

Disable user account help


PRodgers4284

Recommended Posts

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'")); 
?>  

Link to comment
Share on other sites

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'")); 
?>  

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");  

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.