User's Account Activate/Deactivate
Submitted by rinvizle on Friday, November 18, 2016 - 11:56.
User's Account Activate/Deactivate System will teach you how to disable and enable user's account. This simple system gives the information for the user's if their account has been deactivated by the admin. The admin side is the only one can manage the account of every users to activate or deactivate it. And this is compose of PHP, Bootsrap and MySQL, this programs are written in a way that any one can understand and customize for their projects.
UpdateStatus.php - And for the updating of users account to call and to active or deactivate.
Config.php - For the configuration of the system to the database using PDO.
Hope that you learn in this tutorial. And for more updates and programming tutorials don't hesitate to ask and we will answer your questions and suggestions. Don't forget to LIKE & SHARE this website.
Sample Code
Index.php - This script is for the login of the user sessions and for the authenticating if the user is active or deactivate.- <?php
- $username = $_POST['username'];
- $password = $_POST['password'];
- $result = $dbh->prepare("SELECT * FROM tb_users WHERE username= :username AND password= :password");
- $result->bindParam(':username', $username);
- $result->bindParam(':password', $password);
- $result->execute();
- $rows = $result->fetch(PDO::FETCH_NUM);
- if($rows > 0) {
- $result=$dbh->prepare("SELECT * FROM tb_users WHERE username=:username");
- $result->bindParam(':username', $username);
- $result->execute();
- while($row = $result->fetch(PDO::FETCH_ASSOC)){
- $res_id = $row['id'];
- $curr_status = $row['user_status'];
- }
- if($curr_status=='Deactive') {
- $message = "Sorry <b>$username</b>, your account is temporarily deactivated by the admin.";
- }else{
- $_SESSION['id'] = $res_id;
- }
- }
- else{
- $message = 'Username and Password are not exists.';
- }
- }
- ?>
- <?php
- }
- require_once('../config.php');
- $get_userid = $_GET['userid'];
- $result=$dbh->prepare("Select * From tb_users Where id='$get_userid'");
- $result->execute();
- while($row = $result->fetch(PDO::FETCH_ASSOC)){
- echo $curr_status = $row['user_status'];
- }
- if($curr_status == "Active") {
- $sql = "UPDATE tb_users
- SET user_status=?
- WHERE id=?";
- $this_status = "Deactive";
- $q = $dbh->prepare($sql);
- } else {
- $sql = "UPDATE tb_users
- SET user_status=?
- WHERE id=?";
- $this_status = "Active";
- $q = $dbh->prepare($sql);
- }
- ?>
- <?php
- class Database extends pdo {
- private $dbtype;
- private $host;
- private $user;
- private $pass;
- private $database;
- public function __construct(){
- $this->dbtype = 'mysql';
- $this->host = 'localhost';
- $this->user = 'root';
- $this->pass = '';
- $this->database = 'sqlact';
- $dns = $this->dbtype.':dbname='.$this->database.";host=".$this->host;
- parent::__construct( $dns, $this->user, $this->pass );
- }
- }
- $database = new Database();
- $dbh =& $database;
- ?>
Add new comment
- 5634 views