Activate and deactivate concept using php and mysql | 2my4edge

22 August 2013

Activate and deactivate concept using php and mysql

This is the concept for activate and deactivate the account or user to display in the page. that's why we are using this coding. this concept is known by all like block or unblock the user or some other thing. here going to show you that how make activate and deactivate the accounts. this is what using in the most of the social media and more other user management sites are need this concept. let see the details about the coding and some other things.
activate and deactivate concept

DOWNLOAD              LIVE DEMO

this concept is whether we have to display the details of it or not. here i'm showing that in a single page. how to make activate and de-activate the accounts. this concept should not display the details of user and any of the product details in the page when you deactivate the account. let see what are all needed to do that.

FILES :
  1. db.php
  2. index.php
  3. action.php
the above three files must be needed to do this action.

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

here the status is important, because there only the action should be performs. the status must be 0 or 1. 1 means the product is in active state. 0 means not active state.

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 achor tag we just give a link to id of status and used onclick function to activate and de-activate 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
}
?>
In an action page. make the condition in if statement. and use update coding for make activate and de-activate concept. just make 0 and 1 condition. 


RELATED POSTS :






Marquee style in different manner with PHP and MySql






11 comments:

  1. mysql_* in 2013?...

    ReplyDelete
  2. prepare the queries from sql injection

    ReplyDelete
  3. hi, i like your code help me to learn for myself, my question is about the Activate and deactivate it is possible to update database without REFRESH Page!

    i tried myself part of ajax code and i hardly not sure how that works.
    please let me know thanks.

    Alidad@verizon.net

    ReplyDelete
  4. it is showing me the unknown database, plz help me, bilalbinamar@rediff.com

    ReplyDelete
  5. Thank you very much, code works fine.

    ReplyDelete
  6. bina page refresh se kese hoga activ/inactiva

    ReplyDelete
  7. mysql_fetch_object(): supplied argument is not a valid MySQL

    ReplyDelete
  8. Kanhasoft is the PHP Application Development Company based in India and USA. We are promoting business services across USA, UK, Japan, Canada, Singapore, Australia, Sweden, Norway, Switzerland, New Zealand, Germany, South Africa and 45 more.

    ReplyDelete

^