0% found this document useful (0 votes)
29 views4 pages

Bootstrap User Activation Buttons

This document provides code to create a Bootstrap activate/deactivate button for users in a database using PHP. It includes HTML and Bootstrap code to display a table with user info and an activate/deactivate button. It also includes PHP code connected to a database to retrieve user data and scripts to activate or deactivate a user by updating their status field based on the button clicked. When the button is clicked, it sends the user ID to the appropriate PHP script to update the database before redirecting back to the user table.

Uploaded by

Asna Mohamed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

Bootstrap User Activation Buttons

This document provides code to create a Bootstrap activate/deactivate button for users in a database using PHP. It includes HTML and Bootstrap code to display a table with user info and an activate/deactivate button. It also includes PHP code connected to a database to retrieve user data and scripts to activate or deactivate a user by updating their status field based on the button clicked. When the button is clicked, it sends the user ID to the appropriate PHP script to update the database before redirecting back to the user table.

Uploaded by

Asna Mohamed
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Open sidebar

Bootstrap Activate/Deactivate Button

Grace Paul Nyingi

show me how can I create the bootstrap deactivate and activate button for user from database and
show me how can I make it works using php..

To create a Bootstrap deactivate and activate button for a user from a database, you can use HTML,
Bootstrap, and PHP code. Here is an example of how to do this:

HTML and Bootstrap code:

php

Copy code

<table class="table">

<thead>

<tr>

<th>ID</th>

<th>Name</th>

<th>Status</th>

<th>Action</th>

</tr>

</thead>

<tbody>

<?php

// Connect to the database and retrieve user information

$conn = mysqli_connect("localhost", "username", "password", "database_name");

$query = "SELECT * FROM users";


$result = mysqli_query($conn, $query);

// Loop through each user and display their information

while ($row = mysqli_fetch_array($result)) {

echo "<tr>";

echo "<td>" . $row['id'] . "</td>";

echo "<td>" . $row['name'] . "</td>";

// Display the current status of the user

if ($row['status'] == 'active') {

echo "<td><span class='badge bg-success'>Active</span></td>";

} else {

echo "<td><span class='badge bg-danger'>Inactive</span></td>";

// Display the activate/deactivate button

if ($row['status'] == 'active') {

echo "<td><a href='[Link]?id=" . $row['id'] . "' class='btn


btn-danger'>Deactivate</a></td>";

} else {

echo "<td><a href='[Link]?id=" . $row['id'] . "' class='btn btn-success'>Activate</a></td>";

echo "</tr>";

?>

</tbody>

</table>

In this code, we first create an HTML table with four columns: ID, Name, Status, and Action. We then use
PHP to connect to the database and retrieve information about all users. For each user, we display their
ID, Name, and current Status. We also include an Action column that displays a button to activate or
deactivate the user, depending on their current status.

PHP code for activating or deactivating a user:

To make the activate/deactivate button work, we need to create two separate PHP scripts: one to
activate a user and one to deactivate a user. Here is an example of what those scripts might look like:

[Link]:

php

Copy code

<?php

// Connect to the database

$conn = mysqli_connect("localhost", "username", "password", "database_name");

// Retrieve the user ID from the URL parameter

$id = $_GET['id'];

// Update the user's status to "active"

$query = "UPDATE users SET status='active' WHERE id=$id";

mysqli_query($conn, $query);

// Redirect back to the page with the user table

header("Location: [Link]");

?>

[Link]:

php
Copy code

<?php

// Connect to the database

$conn = mysqli_connect("localhost", "username", "password", "database_name");

// Retrieve the user ID from the URL parameter

$id = $_GET['id'];

// Update the user's status to "inactive"

$query = "UPDATE users SET status='inactive' WHERE id=$id";

mysqli_query($conn, $query);

// Redirect back to the page with the user table

header("Location: [Link]");

?>

In these scripts, we first connect to the database using mysqli_connect. We then retrieve the user ID
from the URL parameter using $_GET['id']. We use this ID to update the user's status in the database
using an

ChatGPT Feb 13 Version. Free Research Preview. Our goal is to make AI systems more natural and safe
to interact with. Your feedback will help us improve.

You might also like