Skip to main content

How To Activate De-Activate Account in PHP/MySQL Using PDO


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

  1. <h2>Activate</h2>
  2.  
  3. <table border="1" cellspacing="5" cellpadding="5" width="100%">
  4. <tr>
  5. <th>User Name</th>
  6. <th>Status</th>
  7. <th>Action</th>
  8. </tr>
  9. </thead>
  10. <?php
  11. require_once('db.php');
  12. $result = $conn->prepare("SELECT * FROM tbl_user where status = 'activate' ORDER BY tbl_user_id ASC");
  13. $result->execute();
  14. for($i=0; $row = $result->fetch(); $i++){
  15. $id=$row['tbl_user_id'];
  16. $user_name=$row['user_name'];
  17. ?>
  18. <tr>
  19. <td><label><?php echo $row['user_name']; ?></label></td>
  20. <td><label><?php echo $row['status']; ?></label></td>
  21. <td>
  22. <a href="deactivate.php<?php echo '?tbl_user_id='.$id; ?>" onclick="return confirm(' De-Activate account ( <?php echo $user_name?> ) ? ');">
  23. <button type="submit" class="btn_confirm">
  24. Edit Status
  25. </button>
  26. </a>
  27. </td>
  28. </tr>
  29. <?php } ?>
  30. </tbody>

Update De-Activate Query

  1. <?php
  2. include 'db.php';
  3.  
  4. $get_id=$_REQUEST['tbl_user_id'];
  5.  
  6. $sql = "UPDATE tbl_user SET status ='deactivate' WHERE tbl_user_id = '$get_id' ";
  7.  
  8. $conn->exec($sql);
  9. echo "<script>alert('Successfully Edit The Status!'); window.location='index.php'</script>";
  10. ?>

Table De-Activate Source Code

  1. <h2>De - Activate</h2>
  2.  
  3. <table border="1" cellspacing="5" cellpadding="5" width="100%">
  4. <tr>
  5. <th>User Name</th>
  6. <th>Status</th>
  7. <th>Action</th>
  8. </tr>
  9. </thead>
  10. <?php
  11. require_once('db.php');
  12. $result1 = $conn->prepare("SELECT * FROM tbl_user where status = 'deactivate' ORDER BY tbl_user_id ASC");
  13. $result1->execute();
  14. for($i=0; $row1 = $result1->fetch(); $i++){
  15. $id1=$row1['tbl_user_id'];
  16. $user_name1=$row1['user_name'];
  17. ?>
  18. <tr>
  19. <td><label><?php echo $row1['user_name']; ?></label></td>
  20. <td><label><?php echo $row1['status']; ?></label></td>
  21. <td>
  22. <a href="activate.php<?php echo '?tbl_user_id='.$id1; ?>" onclick="return confirm(' Activate account ( <?php echo $user_name1?> ) ? ');">
  23. <button type="submit" class="btn_confirm">
  24. Edit Status
  25. </button>
  26. </a>
  27. </td>
  28. </tr>
  29. <?php } ?>
  30. </tbody>

Update Activate Query

  1. <?php
  2. include 'db.php';
  3.  
  4. $get_id=$_REQUEST['tbl_user_id'];
  5.  
  6. $sql = "UPDATE tbl_user SET status ='activate' WHERE tbl_user_id = '$get_id' ";
  7.  
  8. $conn->exec($sql);
  9. echo "<script>alert('Successfully Edit The Status!'); window.location='index.php'</script>";
  10. ?>

Output:

Activate the Account.

Result

De-Activate the Account.

Result

After execute the 2 actions.

Result

Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Tags

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.