How To Activate De-Activate Account in PHP/MySQL Using PDO
Submitted by alpha_luna on Monday, May 23, 2016 - 15:52.
Activate De-Activate Account
In this article, we are going to create on How To Activate De-Activate Account in PHP/MySQL Using PDO. In the database table, we have a status column where the value is a activate or deactivate. We are going to use the UPDATE Statement.Table Activate Source Code
- <table border="1" cellspacing="5" cellpadding="5" width="100%">
- <thead>
- <tr>
- </tr>
- </thead>
- <tbody>
- <?php
- require_once('db.php');
- $result = $conn->prepare("SELECT * FROM tbl_user where status = 'activate' ORDER BY tbl_user_id ASC");
- $result->execute();
- for($i=0; $row = $result->fetch(); $i++){
- $id=$row['tbl_user_id'];
- $user_name=$row['user_name'];
- ?>
- <tr>
- <td>
- <a href="deactivate.php<?php echo '?tbl_user_id='.$id; ?>" onclick="return confirm(' De-Activate account ( <?php echo $user_name?> ) ? ');">
- <button type="submit" class="btn_confirm">
- Edit Status
- </button>
- </a>
- </td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
Update De-Activate Query
- <?php
- include 'db.php';
- $get_id=$_REQUEST['tbl_user_id'];
- $sql = "UPDATE tbl_user SET status ='deactivate' WHERE tbl_user_id = '$get_id' ";
- echo "<script>alert('Successfully Edit The Status!'); window.location='index.php'</script>";
- ?>
Table De-Activate Source Code
- <table border="1" cellspacing="5" cellpadding="5" width="100%">
- <thead>
- <tr>
- </tr>
- </thead>
- <tbody>
- <?php
- require_once('db.php');
- $result1 = $conn->prepare("SELECT * FROM tbl_user where status = 'deactivate' ORDER BY tbl_user_id ASC");
- $result1->execute();
- for($i=0; $row1 = $result1->fetch(); $i++){
- $id1=$row1['tbl_user_id'];
- $user_name1=$row1['user_name'];
- ?>
- <tr>
- <td>
- <a href="activate.php<?php echo '?tbl_user_id='.$id1; ?>" onclick="return confirm(' Activate account ( <?php echo $user_name1?> ) ? ');">
- <button type="submit" class="btn_confirm">
- Edit Status
- </button>
- </a>
- </td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
Update Activate Query
- <?php
- include 'db.php';
- $get_id=$_REQUEST['tbl_user_id'];
- $sql = "UPDATE tbl_user SET status ='activate' WHERE tbl_user_id = '$get_id' ";
- echo "<script>alert('Successfully Edit The Status!'); window.location='index.php'</script>";
- ?>
Output:
Activate the Account.


Add new comment
- 642 views