Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    Disable user account help

    I am working on a basic admin area for a website, im want to be able to disable user accounts. I have a field in the database table called "active" which stores a 1 if the user is active or a 0 if the account is inactive. I have the following code that i want to set the active field to "0" to disable the user account, but im not sure of the query is correct:

    The query is:

    PHP Code:
    <?php  

    $username 
    $_GET['username'];

    if (isset(
    $_POST['submit'])) { 

         
    mysql_query("UPDATE users SET active='0' WHERE username=$username");  
    ?>

  • #2
    New Coder
    Join Date
    Dec 2005
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    That would work fine. Just close the if statement.
    PHP Code:
    <?php   

    $username 
    $_GET['username']; 

    if (isset(
    $_POST['submit'])) {  

         
    mysql_query("UPDATE users SET active='0' WHERE username=$username");   
    }
    ?>

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by InsaneRhino View Post
    That would work fine. Just close the if statement.
    PHP Code:
    <?php   

    $username 
    $_GET['username']; 

    if (isset(
    $_POST['submit'])) {  

         
    mysql_query("UPDATE users SET active='0' WHERE username=$username");   
    }
    ?>

    Hey thanks for the reply, yeah it worked ok, but i now need to be able to enable the user account, I thought it was just a matter of changing the "0" to a "1" but it doesnt same to update the table in the database.

    PHP Code:
    $username $_GET['username'];

    if (isset(
    $_POST['submit'])) { 

         
    mysql_query("UPDATE users SET active='1' WHERE username=$username");  
    ?> 

  • #4
    New Coder
    Join Date
    Dec 2005
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    It is that simple, that if statement is still open though. Is it that?

  • #5
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by InsaneRhino View Post
    It is that simple, that if statement is still open though. Is it that?
    Hey this is my full php code, i still doesnt work properly

    PHP Code:
    <?php  

    $username 
    $_GET['username'];

    if (isset(
    $_POST['submit'])) { 

         
    mysql_query("UPDATE users SET active='1' WHERE username=$username");
      
         
         
    //Send out email   

        
    require_once('class.phpgmailer.php');
        
    $mail = new PHPGMailer();
        
    $mail->IsSMTP(); // send via SMTP
        
    $mail->Host 'ssl://smtp.gmail.com'// SMTP servers
        
    $mail->FromName 'Jobs4U.com';
        
    $mail->AddAddress($email);
        
    $mail->Subject 'Jobs4U User Account';
        
    $mail->Body "Your account with the following details:\n\nUsername: $username\nEmail: $email\nForename: $forename\nSurname: $surname\nLocation: $location\n\nhas been disabled.\n\n";  
        
        
    $mail->Send();

    ?>  
               
    <br /> 
    <a href="index.php">Back to main page</a> 
    <br /> 
    <br /> 
    <br /> 
    The account for <b><?php echo $username?></b> has been disabled.

    <?php  
    }  
    else  
    {  
       
    $account mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='$username'")); 
    ?>

  • #6
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    First of all, you have no error checking / recovery logic for your queries. You execute a query and your code continues on blindly, without regard for whether the query failed or not.

    As a first step, I'd suggest implementing proper error checking / recovery. The php manual has examples, and the pages of this forum have countless examples of proper error management.
    John


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •