Wednesday, November 19, 2014

Detail About Activate and Deactivate Concept Using PHP and MySQL

The concept of activate and deactivate is very well-known by all block or unblock user or some other thing. Here, Find a detail about how to make activate and deactivate the accounts. This is used by major social media, and many user management sites need this concept. Let me explain coding for all PHP Programmers.


                                        DOWNLOAD                                       LIVE DEMO

Let's take an example for a single page that how to make activate and de-activate the accounts. It will not display the detail information about users when you deactivate it. Check out below all the necessary files.

1. db.php
2. index.php
3. action.php

Above three are necessary files to complete this action. 

Details About the DATABASE :-

database name : 2my4edge
table name : manage
column names : id, detail, status

The important thing is status because only action should be performs. The status must be zero or one. 1 means – activate state and 0 means – not activate. 

DB.PHP

<?php
$con=mysql_connect('localhost','root','')or die(mysql_error());
$db=mysql_select_db('2my4edge',$con) or die(mysql_error());
?>

INDEX.PHP

<div class="header">
<div class="left"> Details </div>
<div class="right"> Status </div>

<?php 
include('db.php');
$select=mysql_query("select * from manage");
while($row=mysql_fetch_array($select))
{
$id=$row['id'];
$data=$row['detail'];
$status=$row['status'];
?>
<div class="left1"> <?php echo $data?> </div>
<div class="right1"> 
<?php
if(($status)=='0')
{
?>
<a href="action.php?status=<?php echo $row['id'];?>" 
 class="act" onclick="return confirm('Activate <?php echo $data?>');"> Deactivate </a>
<?php
}
if(($status)=='1')
{
?>
<a href="action.php?status=<?php echo $row['id'];?>" 
 class="deact" onclick="return confirm('De-activate <?php echo $data?>');"> Activate</a>
<?php
}
?>
</div>
<?php }?> 
</div>
In an anchor tag, we just give a link to id of status, and used on click function to activate and de-activate the concept. If the status is 0 means activate and 1 means de-activate.

ACTION.PHP

<?php
include('db.php');
if(isset($_GET['status']))
{
$status1=$_GET['status'];
$select=mysql_query("select * from manage where id='$status1'");
while($row=mysql_fetch_object($select))
{
$status_var=$row->status;
if($status_var=='0')
{
$status_state=1;
}
else
{
$status_state=0;
}
$update=mysql_query("update manage set status='$status_state' where id='$status1' ");
if($update)
{
header("Location:index.php");
}
else
{
echo mysql_error();
}
}
?>
<?php
}
?>

Make the condition in if statement and use updated coding for making activate and de-activate the concept. You just need to make 0 and 1 condition. 

0 comments:

Post a Comment